当前位置: 技术问答>java相关
谁有数据库连接通用Bean 急!
来源: 互联网 发布时间:2015-06-16
本文导语: 谁有数据库连接通用Bean 急! | package untitled1; import java.sql.*; import java.util.*; import java.io.*; public class opendb { String sDBDriver= "sun.jdbc.odbc.JdbcOdbcDriver"; String sConnStr= "jdbc:odbc:jsp"; ...
谁有数据库连接通用Bean 急!
|
package untitled1;
import java.sql.*;
import java.util.*;
import java.io.*;
public class opendb
{ String sDBDriver= "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr= "jdbc:odbc:jsp";
Connection conn= null;
ResultSet RS= null;
Statement st = null;
public opendb()
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e)
{ System.out.println("opendb():"+e.getMessage()); }
}
//-----------------------executeQuery-------------
public ResultSet executeQuery(String sql)
{
try{
conn=DriverManager.getConnection(sConnStr,"sa","");
Statement stmt=conn.createStatement();
RS = stmt.executeQuery(sql);
return RS;
}
catch(Exception ex){
System.out.println("aq.executeQuery:"+ex.getMessage());}
return RS;
}
//--------------executeUpdate-----------------
public int executeUpdate(String up_str) throws SQLException
{
try{
conn=DriverManager.getConnection(sConnStr,"sa","");
st = conn.createStatement() ;
st.executeUpdate(up_str) ;
return 1 ;}
catch (Exception e){
System.out.println("executepdate:ʧ°Ü"+e.toString() ) ;
return -1;}
}
}
import java.sql.*;
import java.util.*;
import java.io.*;
public class opendb
{ String sDBDriver= "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr= "jdbc:odbc:jsp";
Connection conn= null;
ResultSet RS= null;
Statement st = null;
public opendb()
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e)
{ System.out.println("opendb():"+e.getMessage()); }
}
//-----------------------executeQuery-------------
public ResultSet executeQuery(String sql)
{
try{
conn=DriverManager.getConnection(sConnStr,"sa","");
Statement stmt=conn.createStatement();
RS = stmt.executeQuery(sql);
return RS;
}
catch(Exception ex){
System.out.println("aq.executeQuery:"+ex.getMessage());}
return RS;
}
//--------------executeUpdate-----------------
public int executeUpdate(String up_str) throws SQLException
{
try{
conn=DriverManager.getConnection(sConnStr,"sa","");
st = conn.createStatement() ;
st.executeUpdate(up_str) ;
return 1 ;}
catch (Exception e){
System.out.println("executepdate:ʧ°Ü"+e.toString() ) ;
return -1;}
}
}