📄 conn.java
字号:
package data;
import java.sql.*;
public class Conn {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String drivername = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:firm";
public static Connection getCon() throws Exception {
try {
Class.forName(drivername);
con = DriverManager.getConnection(url,"sa","");
return con;
} catch (SQLException e) {
System.err.println("getCon" + e.getMessage());
throw e;
}
}
public static Statement getStmt() {
try {
con = getCon();
Statement stmt = con.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
return stmt;
} catch (Exception e) {
System.err.println("getStmt" + e.getMessage());
return null;
}
}
public static ResultSet executeQuery(String sql) {
try {
stmt = getStmt();
rs = stmt.executeQuery(sql);
} catch (Exception e) {
System.err.println("executeQuery" + e.getMessage());
}
return rs;
}
public static int executeUpdate(String sql) {
int count = 0;
stmt = getStmt();
try {
count = stmt.executeUpdate(sql);
} catch (Exception e) {
count = -2;
System.err.println("executeUpdata" + e.getMessage());
return count;
} finally {
}
return count;
}
public static void close() {
try {
if (rs != null) {
rs.close();
rs = null;
}
} catch (Exception e) {
System.out.println("closers" + e.getMessage());
}
try {
if (stmt != null) {
stmt.close();
stmt = null;
}
} catch (Exception e) {
System.out.println("closestmt" + e.getMessage());
}
try {
if (con != null) {
con.close();
con = null;
}
} catch (Exception e) {
System.out.print("closecon" + e.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -