?? vocationcondb.java
字號:
package 畢業設計;
import java.sql.*;
import javax.swing.JOptionPane;
import java.util.Vector;
public class VocationConDB {
private Connection con;
private Statement st;
private ResultSet rs;
private PreparedStatement pst;
public VocationConDB() {
//*************************連接數據庫*************************************
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
System.out.println("Driver 出錯");
}
try {
String url = "jdbc:odbc:chenhaiLibrary";
con = DriverManager.getConnection(url);
st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
} catch (SQLException ex1) {
System.out.println("lib 出錯");
}
}
//**************************添加讀者職業************************************
public boolean AddVocation(String Vocation) {
boolean Success = true;
try {
String strSQL = "insert Vocation values ( '" + Vocation + "')";
pst = con.prepareStatement(strSQL);
pst.executeUpdate();
pst.close();
} catch (SQLException ex) {
Success = false;
}
return Success;
}
//******************************查詢所有讀者職業********************************
public Vector SearchAll() {
Vector vt = new Vector();
try {
String str = "select * from Vocation";
rs = st.executeQuery(str);
while (rs.next()) {
Vector temp = new Vector();
temp.add(rs.getString(1));
temp.add(rs.getString(2));
vt.add(temp);
}
rs.close();
} catch (SQLException ex) {
}
return vt;
}
//*****************************查詢讀者職業*********************************
public Vector SearchVocation(String Vocation) {
Vector vt = new Vector();
try {
String str = "select * from Vocation where VocationName like '%" +
Vocation + "%'";
rs = st.executeQuery(str);
while (rs.next()) {
Vector temp = new Vector();
temp.add(rs.getString(1));
temp.add(rs.getString(2));
vt.add(temp);
}
rs.close();
} catch (SQLException ex) {
}
return vt;
}
//*********************************更新讀者職業*****************************
public boolean UpdateVocation(int Id, String VocationName) {
boolean Success = true;
try {
String strSQL = "update Vocation set VocationName = '" +
VocationName +
"' where Id = " + Id;
pst = con.prepareStatement(strSQL);
pst.executeUpdate();
pst.close();
} catch (SQLException ex) {
Success = false;
}
return Success;
}
//*******************************刪除讀者職業*******************************
public void DeleteVocation(int Id) {
try {
String strSQL = "delete from Vocation where Id = " + Id;
pst = con.prepareStatement(strSQL);
pst.executeUpdate();
pst.close();
} catch (SQLException ex) {
}
}
//*****************************關閉數據庫連接*********************************
public void CloseVocationDB() {
try {
st.close();
con.close();
} catch (SQLException ex) {
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -