?? conndb.java
字號:
package beans;
import java.sql.*;
public class connDB{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public connDB(){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(java.lang.ClassNotFoundException e){
System.err.println(e.getMessage());
}
}
/***************************************************
*method name: executeQuery()
*功能:執行查詢操作
*return value: ResultSet
*2005-12-05
****************************************************/
public ResultSet executeQuery(String sql){
try{
conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_bookmanage;user=sa;password=");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(sql);
}catch(SQLException ex){
System.err.println(ex.getMessage());
}
return rs;
}
/***************************************************
*method name: executeUpdate()
*功能:執行更新操作
*return value: int
*2005-12-05
****************************************************/
public int executeUpdate(String sql){
int result=0;
try{
conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_bookmanage;user=sa;password=");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
result=stmt.executeUpdate(sql);
}catch(SQLException ex){
result=0;
}
return result;
}
/***************************************************
*method name: close()
*功能:關閉數據庫鏈接
*return value: void
*2005-12-05
****************************************************/
public void close(){
try {
if (rs != null) rs.close();
}
catch (Exception e) {
e.printStackTrace(System.err);
}
try {
if (stmt != null) stmt.close();
}
catch (Exception e) {
e.printStackTrace(System.err);
}
try {
if (conn != null) {
conn.close();
}
}
catch (Exception e) {
e.printStackTrace(System.err);
}
}
/***************************************************
*method name: chStr_In()
*method function: change coding "'" to Char(1)
*return value: String
*2005-12-05
****************************************************/
public String chStr_In(String str){
if(str==null){
str="";
}else{
try{
str=(new String(str.getBytes("iso-8859-1"),"GB2312")).trim();
str=str.replace('\'',(char)1);
}catch(Exception e){
e.printStackTrace(System.err);
}
}
return str;
}
/***************************************************
*method name: chStr_Out()
*method function: change coding Char(1) to "'"
*return value: String
*2005-12-05
****************************************************/
public String chStr_Out(String str){
if(str==null){
str="";
}else{
try{
str=str.replace((char)1,'\'');
}catch(Exception e){
e.printStackTrace(System.err);
}
}
return str;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -