📄 condb.java
字号:
package condb;
import java.sql.*;
public class ConDB{
private static Connection con;
private Statement stmt;
private ResultSet rs;
private static final String drivername="com.microsoft.jdbc.sqlserver.SQLServerDriver";
private static final String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=YCJX;user=sa;password=sa";
public ConDB(){
}
public static synchronized Connection getCon() throws Exception {
try{
Class.forName(drivername);
con=DriverManager.getConnection(url);
return con;
}
catch(SQLException e){
System.err.println(e.getMessage());
throw e;
}
}
public Statement getStmtread(){
try{
con=getCon();
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
return stmt;
}
catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
}
public ResultSet getRs(String sql) throws Exception{
stmt=getStmtread();
rs=stmt.executeQuery(sql);
return rs;
}
public int executeUpdate(String sql){
int i=-1;
stmt = getStmtread();
try{
i = stmt.executeUpdate(sql);
}
catch(Exception e)
{
System.err.println(e.getMessage());
e.printStackTrace();
}
return i;
}
public void close(){
try{
if(rs != null){
rs.close();
rs=null;
}
}
catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
try{
if(stmt != null){
stmt.close();
stmt=null;
}
}
catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
try{
if(con != null){
con.close();
con=null;
}
}
catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -