?? db.java
字號:
package numb1.com;
import java.lang.*;
import java.sql.*;
public class db{
private Connection con;
private Statement st;
private ResultSet rs;
private String host="localhost";
private String user="root";
private String pw="";
private String db="numb1";
private String Dri="com.mysql.jdbc.Driver";
private String url="jdbc:mysql://"+host+"/"+db;
public String getStr(String s){
String str=s;
try{
byte b[]=str.getBytes("ISO-8859-1");
str=new String(b);
return str;
}
catch(Exception e){return null;}
}
public String gb2iso(String qs){
try{
if (qs == null) return "NULL";
else return new String(qs.getBytes("gb2312"),"iso-8859-1");
}
catch(Exception e){
System.out.print("gb2iso error:"+e.getMessage());
}
return "NULL";
}
public void close(){//關閉連接
try{
if(rs!=null)rs.close();
}catch(Exception e){
System.out.print("rs"+e.getMessage());
}
try{
if(st!=null)st.close();
}catch(Exception e){
System.out.print("st"+e.getMessage());
}
try{
if(con!=null)con.close();
}catch(Exception e){
System.out.print("con"+e.getMessage());
}
}
public ResultSet query(String sql)throws Exception{
try{
Class.forName(Dri).newInstance();
con=DriverManager.getConnection(url,user,pw);
st=con.createStatement();
rs=st.executeQuery(sql);
return rs;
}catch(SQLException e){
System.out.print(e.getMessage());
return null;
}
}
public void update(String sql)throws Exception{
try{
Class.forName(Dri).newInstance();
con=DriverManager.getConnection(url,user,pw);
st=con.createStatement();
st.executeUpdate(sql);
st.close();
con.close();
}catch(SQLException e){
System.out.print(e.getMessage());
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -