?? frmclszdb.java
字號(hào):
/**
*該類用于連接與操作ZYSFDB數(shù)據(jù)庫中的數(shù)據(jù)表
*編寫者:劉鳳勇
*編寫日期:2005-09-17
*備注:
**/
package myprojects.frmCLSZDb;
import java.sql.*;
public class FrmCLSZDb
{
private String dbDriver = null;//驅(qū)動(dòng)字符串
private String dbConnStr = null;//連接字符串
private Connection conn; //連接對(duì)象
private Statement stmt; //JDBC聲明
private String psSQL = null;
public ResultSet prs = null;
/**
*函數(shù)名:getConnection
*編寫者:劉鳳勇
*功 能:數(shù)據(jù)庫連接初始化,得到數(shù)據(jù)庫的連接
*輸入?yún)?shù):無
*返回值類型: BOOLEAN
*備 注:
**/
public boolean getConnection()
{
try
{
dbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
dbConnStr = "jdbc:odbc:Dbserver";
Class.forName(dbDriver); //加載驅(qū)動(dòng)程序
conn = DriverManager.getConnection(dbConnStr); //創(chuàng)建連接
conn.setAutoCommit(false); //設(shè)置不自動(dòng)提交
conn.setTransactionIsolation(conn.TRANSACTION_READ_COMMITTED); //設(shè)置事務(wù)級(jí)別
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY); //創(chuàng)建一個(gè)JDBC聲明
}
catch(Exception e) //捕獲數(shù)據(jù)庫連接過程中的異常
{
System.out.print(e.getMessage());
e.printStackTrace();
return false;
}
return true;
}
/**
*函數(shù)名:getComboInitalDate
*編寫者:劉鳳勇
*功 能:從Constants數(shù)據(jù)表中獲取frmCLSZ窗體中下拉列表框cmbYPJX的初始化數(shù)據(jù)
*輸入?yún)?shù):無
*返回值類型:ResultSet
*備 注:
**/
public ResultSet getComboInitalData()throws Exception
{
psSQL = "select DISTINCT Type from Constants";
prs = stmt.executeQuery(psSQL);
return prs;
}
/**
*函數(shù)名:getTableInitalData
*編寫者:劉鳳勇
*功 能:通過frmCLSZ窗體中下拉列表框cmbYPJX的數(shù)據(jù)動(dòng)態(tài)查詢數(shù)據(jù)表Constants
*輸入?yún)?shù):String type
*返回值類型:ResultSet
*備 注:
**/
public ResultSet getTableInitalData(String type)throws Exception
{
psSQL = "select Constant from Constants where Type='"+type+"'";
prs = stmt.executeQuery(psSQL);
return prs;
}
/**
*函數(shù)名:RemoveAllItems
*編寫者:劉鳳勇
*功 能:通過frmCLSZ窗體中下拉列表框cmbYPJX的數(shù)據(jù)為條件刪除Constants數(shù)據(jù)表中的符合條件的數(shù)據(jù)
*輸入?yún)?shù):String type
*返回類型:無
*備 注:
**/
public void RemoveAllItems(String type) throws Exception
{
psSQL = "DELETE FROM Constants WHERE (Type = '"+type+"')";
try
{
stmt.executeUpdate(psSQL);
conn.commit();
}
catch(SQLException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
//如果在執(zhí)行刪除的過程中出現(xiàn)異常,事物處理就回滾到執(zhí)行前的狀態(tài)
try
{
conn.rollback();
}
catch(SQLException e1)
{;}
}
}
/**
*函數(shù)名:AddDataInConstants
*編寫者:劉鳳勇
*功 能:把frmCLSZ窗體中表格tbXTSZNR中的數(shù)據(jù)依次寫入Constants數(shù)據(jù)表
*輸入?yún)?shù):String type,String Constant
*返回值類型:無
*備 注:
**/
public void AddDataInConstants(String type,String Constant)throws Exception
{
psSQL = "insert Constants (Type,Constant) values('"+type+"','"+Constant+"')";
try
{
stmt.executeUpdate(psSQL);
conn.commit();
}
catch(SQLException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
//如果在執(zhí)行刪除的過程中出現(xiàn)異常,事物處理就回滾到執(zhí)行前的狀態(tài)
try
{
conn.rollback();
}
catch(SQLException e1)
{;}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -