?? publishcondb.java~9~
字號:
package 畢業(yè)設計;
import java.sql.*;
import javax.swing.JOptionPane;
import java.util.Vector;
public class PublishConDB {
private Connection con;
private Statement st;
private ResultSet rs;
private PreparedStatement pst;
public PublishConDB()
{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
System.out.println("Driver 出錯");
}
try {
String url = "jdbc:odbc:lib";
con = DriverManager.getConnection(url);
st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
} catch (SQLException ex1) {
System.out.println("lib 出錯");
}
}
public void AddPublish(String Publish)
{
try {
String strSQL = "insert Publish values ( '" + Publish +"')";
pst = con.prepareStatement(strSQL);
pst.executeUpdate();
pst.close();
} catch (SQLException ex) {
}
}
public Vector SearchAll()
{
Vector vt = new Vector();
try {
String str = "select * from Publish";
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 SearchPublish(String Publish)
{
Vector vt = new Vector();
try {
String str = "select * from Publish where PublishName like '%" +
Publish + "%'";
rs = st.executeQuery(str);
while (rs.next()) {
vt.add(rs.getString(2));
}
rs.close();
} catch (SQLException ex) {
}
return vt;
}
public void UpdatePublish(String Id, String PublishName)
{
try {
String strSQL = "update Publish set PublishName = '" + PublishName +
"' where Id = '" + Id + "'";
pst = con.prepareStatement(strSQL);
pst.executeUpdate();
pst.close();
} catch (SQLException ex) {
}
}
public void DeletePublish(String Id)
{
try {
String strSQL = "delete from Publish where Id = '" + Id + "'";
pst = con.prepareStatement(strSQL);
pst.executeUpdate();
pst.close();
} catch (SQLException ex) {
}
}
public void ClosePublishDB()
{
try {
st.close();
con.close();
} catch (SQLException ex) {
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -