condb.java

来自「mysql数据库连接(java),提供错误回滚.」· Java 代码 · 共 64 行

JAVA
64
字号

package Condb;
import java.sql.*; 
import java.lang.*;
import java.io.*;

public class Condb{ 
public String dbname="jdbc:mysql://localhost:3306/wjl?useUnicode=true&characterEncoding=gbk"; 
Connection con=null; 
Statement stmt=null; 
ResultSet rs=null;
private String User="root"; 
private String Pass="lenovo"; 
public Condb(){
try{
Class.forName("org.gjt.mm.mysql.Driver");
}catch(ClassNotFoundException e1){
System.out.print(e1);
}try{
con=DriverManager.getConnection(dbname,User,Pass);
}catch(SQLException e3){
System.err.print(e3);}
}

public ResultSet executeQuery(String sql) 
{ 
try{ 
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); 
ResultSet rs=stmt.executeQuery(sql); 

}catch(SQLException e2){
 System.err.print(e2);
}
return rs; 
}

public int executeUpdate(String sql) 
{ 
int rt=0;
try{
stmt=con.createStatement(); 
rt=stmt.executeUpdate(sql); 
}catch(SQLException ex) 
{
System.err.print(ex);
}
return rt;
}

void close(){
try{
if(con!=null){ 
      con.close();}
}catch(Exception e){
System.out.print(e);}
try{
if(rs!=null){
rs.close();}
}catch(Exception e){
System.out.print(e);}
}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?