📄 connectiondb.java
字号:
package student.manage.javaConnction;
import java.sql.*;
import java.util.ArrayList;
public class connectionDB {
Connection con = null;
Statement state = null;
ResultSet result = null;
public Statement getConnectionDB() {
try {
String JDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(JDriver);
} catch (java.lang.ClassNotFoundException e) {
System.out.println("ForName:" + e.getMessage());
}
try {
String conURL = "jdbc:odbc:connector";
con = DriverManager.getConnection(conURL, "sa", "sa");
//state = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
state = con.createStatement();
} catch (SQLException e) {
System.out.println("SQLException:" + e.getMessage());
}
return state;
}
public void Close() {
CloseStmt();
CloseRs();
CloseCon();
}
/**
* 连接关闭
*/
public void CloseRs() {
try {
if (result != null) {
result.close();
}
}
catch (Exception ex) {}
}
/**
*
*/
public void CloseCon() {
try {
if (con != null) {
con.close();
}
}
catch (Exception ex) {}
}
/**
*
*/
public void CloseStmt() {
try {
if (state != null) {
state.close();
}
}
catch (Exception ex) {}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -