?? dataprocess.java
字號:
/*
* 創建日期 2005-5-1
*
* TODO 要更改此生成的文件的模板,請轉至
* 窗口 - 首選項 - Java - 代碼樣式 - 代碼模板
*/
package com.db;
/**
* @author ligang
*
* TODO 要更改此生成的類型注釋的模板,請轉至
* 窗口 - 首選項 - Java - 代碼樣式 - 代碼模板
*/
import java.sql.*;
//數據庫操作輔助類
public class DataProcess {
DataProcess(){
}
//連接數據庫
public static Connection getConnection()
{
String CLASSFORNAME="sun.jdbc.odbc.JdbcOdbcDriver";
String SERVANDDB = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=F:/J2EE_DEVELOP/workplace/luntan/luntan.mdb";
Connection con;
try
{
Class.forName(CLASSFORNAME);
con = DriverManager.getConnection(SERVANDDB);
return con;
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
}
//獲取結果集總數
public static int nCount(String SQL)
{
Connection myConnection = getConnection();
int count = 0;
try
{
Statement stm = myConnection.createStatement();
ResultSet result = stm.executeQuery(SQL);
if(result.next())
{
count = result.getInt(1);
result.close();
}
stm.close();
myConnection.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return count;
}
/**插入或刪除語句*/
public static boolean ExeQuery(String SQL)
{
Connection con = getConnection();
try
{
Statement stmt = con.createStatement();
stmt.executeUpdate(SQL);
stmt.close();
con.close();
return true;
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
}
//獲取結果集
public static ResultSet getResult(String SQL,Connection con)
{
ResultSet rs = null;
try{
Statement stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
}catch(SQLException e)
{
e.printStackTrace();
}
return rs;
}
//關閉連接
public static void CloseConnection(Connection con)
{
try
{
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//關閉結果集
public static void CloseResultSet(ResultSet rs)
{
try
{
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -