📄 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");
//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//sql2005
}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_dcmanage;user=sa;password=");
// conn=DriverManager.getConnection("jdbc:sqlserver://localhost;DatabaseName=db_dcmanage;user=sa;password=25814469");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
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:sqlserver://localhost;DatabaseName=db_dcmanage;user=sa;password=25814469");
conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_dcmanage;user=sa;password=");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
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 + -