📄 link_db.java
字号:
package useBean;
import java.sql.*;
public class Link_db{
private static Connection con=null;
private Statement state=null;
private ResultSet rs=null;
/***************************************************
*method name: init()<br>
*method function: Set up DataBase Statement<br>
*return value: void<br>
*method function: no<br>
*amend: crazyadept<br>
* 2004/8/2<br>
****************************************************/
public void init(Connection con){
try{
state=Link_db.con.createStatement();
}catch(Exception e){
System.out.println("init");
System.out.println(e.getMessage());
}
}
/***************************************************
*method name: close()<br>
*method function: close DataBase Connection<br>
*return value: void<br>
*method function: no<br>
*amend: crazyadept<br>
* 2004/7/28<br>
****************************************************/
public void close(){
try{
if (rs !=null){
rs.close();
rs=null;
}
}catch(Exception e){
System.out.println("rs");
System.out.println(e.getMessage());
}
try{
if(state!=null){
state.close();
state=null;
}
}catch(Exception e){
System.out.println("state");
System.out.println(e.getMessage());
}
try{
if(con!=null){
con.close();
state=null;
}
}catch(Exception e){
System.out.println("close");
System.out.println(e.getMessage());
}
}
/***************************************************
*method name: select()<br>
*method function: select DataBase data<br>
*return value: int<br>
* k=-10; on word<br>
* k=0; on record<br>
* k=-1; have exception <br>
* k>0; it is ok<br>
*parameter explain: no<br>
*amend: crazyadept<br>
* 2004/8/2<br>
****************************************************/
public int select(String sql){
int k=-10;
this.init(Link_db.getCon());
try{
k=0;
rs=state.executeQuery(sql);
if(rs.next()){
k=k+1;
}
}catch(Exception e){
k=-1;
System.out.println("select");
System.out.println(e.getMessage());
this.close();
}
this.close();
return k;
}
/***************************************************
*method name: update()<br>
*method function: updata,insert,delete<br>
*return value: int<br>
* k=-10; on work <br>
* k=0; on insert data<br>
* k=-1; hava exception<br>
* k>0; work is ok<br>
*parameter explain: no<br>
*amend: crazyadept<br>
* 2004/8/2<br>
****************************************************/
public int update(String sql){
int k=-10;
this.init(Link_db.getCon());
try{
k=0;
k=state.executeUpdate(sql);
}catch(Exception e){
k=-1;
System.out.println("update");
System.out.println(e.getMessage());
}
this.close();
return k;
}
/***************************************************
*method name: getCon()<br>
*method function: get DataBase Connection<br>
*return value: Connection<br>
* con; return DataBase Connection<br>
*parameter explain: no<br>
*amend: crazyadept<br>
* 2004/8/2
****************************************************/
public static synchronized Connection getCon(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Community","","");
}catch(Exception e){
System.out.println("getCon");
System.out.println(e.getMessage());
}
return con;
}
/***************************************************
*method name: chStr()<br>
*method function: change coding<br>
*return value: String<br>
* return Chainese<br>
*parameter explain: str<br>
*amend: crazyadept<br>
* 2004/8/2<br>
****************************************************/
public String chStr(String str){
if(str==null){
str="";
}else{
try{
str=(new String(str.getBytes("iso-8859-1"),"GB2312")).trim();
}catch(Exception e){
System.out.println("chStr");
System.out.println(e.getMessage());
}
}
return str;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -