/**
* Title:SQL Server Connection Pool
* Description:Use Connection
* Copyright:Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/public class SQLConn {
String url = "jdbc:weblogic:mssqlserver4:ESASDB@cxg";
String strDriver="weblogic.jdbc.mssqlserver4.Driver";
String login="sa";
String password="";
Connection conn=null;//connection object /**Default constructor to connect database
* user is 'sa',no password
*/
public SQLConn() {
try{
Class.forName(strDriver);
conn=DriverManager.getConnection(url,login,password);
}
catch(ClassNotFoundException e){
System.out.println("databaseName"+e.getMessage());
}
catch(SQLException e){
System.out.println("databaseName"+e.getMessage());
}
}
/**connection method
*set up connection and return Connection object
*/
public Connection setupConn(){
Connection conn=null;
try{
Class.forName(strDriver);
conn=DriverManager.getConnection(url,login,password);
}
catch(ClassNotFoundException e){
System.out.println("databaseName"+e.getMessage());
}
catch(SQLException e){
System.out.println("databaseName"+e.getMessage());
}
return conn;
}
/**close database method
* close database
*/ public void closeDatabase(Connection conn,Statement stmt ){
try{
stmt.close();
conn.close();
}
catch(java.sql.SQLException e){
}
}
/**Query method
* execute query and return ResultSet object
* use default constructor Connection
*/ public ResultSet exeQuery(String strSql){
Statement stmt;
ResultSet rs=null;
try{
stmt=conn.createStatement();
rs=stmt.executeQuery(strSql);
}
catch(java.sql.SQLException e){
System.out.println("databaseName"+e.getMessage());
}
return rs;//return result set
}
* Title:SQL Server Connection Pool
* Description:Use Connection
* Copyright:Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/public class SQLConn {
String url = "jdbc:weblogic:mssqlserver4:ESASDB@cxg";
String strDriver="weblogic.jdbc.mssqlserver4.Driver";
String login="sa";
String password="";
Connection conn=null;//connection object /**Default constructor to connect database
* user is 'sa',no password
*/
public SQLConn() {
try{
Class.forName(strDriver);
conn=DriverManager.getConnection(url,login,password);
}
catch(ClassNotFoundException e){
System.out.println("databaseName"+e.getMessage());
}
catch(SQLException e){
System.out.println("databaseName"+e.getMessage());
}
}
/**connection method
*set up connection and return Connection object
*/
public Connection setupConn(){
Connection conn=null;
try{
Class.forName(strDriver);
conn=DriverManager.getConnection(url,login,password);
}
catch(ClassNotFoundException e){
System.out.println("databaseName"+e.getMessage());
}
catch(SQLException e){
System.out.println("databaseName"+e.getMessage());
}
return conn;
}
/**close database method
* close database
*/ public void closeDatabase(Connection conn,Statement stmt ){
try{
stmt.close();
conn.close();
}
catch(java.sql.SQLException e){
}
}
/**Query method
* execute query and return ResultSet object
* use default constructor Connection
*/ public ResultSet exeQuery(String strSql){
Statement stmt;
ResultSet rs=null;
try{
stmt=conn.createStatement();
rs=stmt.executeQuery(strSql);
}
catch(java.sql.SQLException e){
System.out.println("databaseName"+e.getMessage());
}
return rs;//return result set
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货