📄 conn.java
字号:
/*
* Created on 2004-9-18
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.bwm.db;
import java.sql.*;
/**
*class explain:Database connection<br>
*set up name: crazyadept<br>
*set up time: 11/22/2004
*/
public class Conn {
private static Connection con;
private Statement stmt;
private ResultSet rs;
private PreparedStatement pstmt;
private static int CON_COUNT=0;
/**
*method explain: Auto Connection DataBase<br>
*set up name: crazyadept<br>
*change time: 12/20/2004
*/
public static synchronized Connection getCon()throws Exception{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:School","","");
CON_COUNT++;
return con;
}catch(SQLException e){
System.err.println(e.getMessage());
throw e;
}
}
/**
*return value: in order select in SQL<br>
*set up name: crazyadept<br>
*change time: 12/20/2004
*/
public Statement getStmtread(){
try{
con=getCon();
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
return stmt;
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
}
/**
*return value: Data<br>
*parameter: SQL select sentence<br>
*set up name: crazyadept<br>
*change time: 11/29/2004
*/
public ResultSet getRs(String sql){
try{
stmt=getStmtread();
rs=stmt.executeQuery(sql);
return rs;
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
}
/**
*return value: not in order select in str SQL<br>
*set up name: crazyadept<br>
*set up time: 11/29/2004<br>
*change time: 11/29/2004
*/
public Statement getStmt(){
try{
con=getCon();
stmt=con.createStatement();
return stmt;
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
}
/**
*return value: Connection count<br>
*set up name: crazyadept<br>
*change time: 12/01/2004
*/
public int getConcount(){
return CON_COUNT;
}
/**
*return value: DataBase pretreatment sentense<br>
*parameter: like as SQL sentence<br>
*set up name: crazyadept<br>
*set up time: 11/29/2004<br>
*change time: 11/29/2004
*/
public PreparedStatement getPstmt(String sql){
try{
con=getCon();
pstmt=con.prepareStatement(sql);
return pstmt;
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
}
/**
*method explain: Close DataBase Connection<br>
*set up name: crazyadept<br>
*set up time: 11/29/2004<br>
*change time: 11/29/2004
*/
public synchronized void close(){
try{
if(rs!=null){
rs.close(); rs=null;
}
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
try{
if(stmt!=null){
stmt.close(); stmt=null;
}
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
try{
if(con!=null){
con.close(); con=null; CON_COUNT--;
}
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -