📄 publishcondb.java
字号:
package 毕业设计;
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:chenhaiLibrary";
con = DriverManager.getConnection(url);
st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
} catch (SQLException ex1) {
System.out.println("lib 出错");
}
}
//*************************添加图书出版社*************************************
public boolean AddPublish(String Publish) {
boolean Success = true;
try {
String strSQL = "insert Publish values ('" + Publish + "')";
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 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()) {
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 UpdatePublish(int Id, String PublishName) {
boolean Success = true;
try {
String strSQL = "update Publish set PublishName = '" + PublishName +
"' where Id = " + Id;
pst = con.prepareStatement(strSQL);
pst.executeUpdate();
pst.close();
} catch (SQLException ex) {
Success = false;
}
return Success;
}
//***************************删除图书出版社***********************************
public void DeletePublish(int 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 + -