?? conn.java
字號:
package com.ww.j2ee;
import java.sql.*;
public class Conn{
private static Connection con;
private ResultSet rs;
private Statement st;
private static final String drivername="com.mysql.jdbc.Driver";
private static final String url="jdbc:mysql://localhost:3306/j2ee_booksys?useUnicode=true&characterEncoding=GB2312";
private static final String user="root";
private static final String password="root";
public static synchronized Connection getCon() throws Exception{
try{
Class.forName(drivername);
con=DriverManager.getConnection(url,user,password);
return con;
}catch(Exception e){
System.err.println(e.getMessage());
throw e;
}
}
public Statement getSt(){
try{
con=getCon();
st=con.createStatement();
return st;
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
}
public ResultSet getRs(String sql){
try{
st=getSt();
rs=st.executeQuery(sql);
return rs;
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
}
public synchronized void close(){
try{
if(st!=null){
st.close();
st=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 + -