📄 dbconn.java
字号:
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLXML;
import java.sql.Statement;
public class DBConn {
Connection conn;
public DBConn() throws SQLException {
String userName = "root";
String userPwd = "123456";
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Cert_DB", userName, userPwd);
}
public ResultSet getResult(String query) throws SQLException {
Statement stm = conn.createStatement();
return stm.executeQuery(query);
}
public int execute(String query) throws SQLException {
Statement stm = conn.createStatement();
return stm.executeUpdate(query);
}
public Statement createStatement() throws SQLException {
return conn.createStatement();
}
public PreparedStatement prepareStatement(String sql) throws SQLException {
return conn.prepareStatement(sql);
}
public void close() throws SQLException {
conn.close();
}
public void setReadOnly(boolean readOnly) throws SQLException {
conn.setReadOnly(readOnly);
}
public void rollback() throws SQLException {
conn.rollback();
}
public boolean isValid(int timeout) throws SQLException {
return conn.isValid(timeout);
}
public boolean isReadOnly() throws SQLException {
return conn.isReadOnly();
}
public boolean isClosed() throws SQLException {
return conn.isClosed();
}
public SQLXML createSQLXML() throws SQLException {
return conn.createSQLXML();
}
public NClob createNClob() throws SQLException {
return conn.createNClob();
}
public Clob createClob() throws SQLException {
return conn.createClob();
}
public Blob createBlob() throws SQLException {
return conn.createBlob();
}
public void commit() throws SQLException {
conn.commit();
}
static {
try {
Class.forName("org.gjt.mm.mysql.Driver");
} catch (ClassNotFoundException classNotFoundException) {
throw new ExceptionInInitializerError(classNotFoundException);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -