DBManager.java
代码
/*
* 创建日期 2004-11-12
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
/**
* @author
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
import java.sql.*;
import javax.swing.JOptionPane;
public class DBManager {
ResultSet rs1;
public ResultSet getResult(String s1) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException e) {
System.out.println(e.toString());
JOptionPane.showMessageDialog(null,"Roger:获取结果集时驱动无法加载!\nSystem:"+e.toString());
}
try {
Connection con1=DriverManager.getConnection("jdbc:odbc:BookManagerDB","admin","sa");
Statement stat1=con1.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs1=stat1.executeQuery(s1);
return rs1;
}catch(SQLException e) {
System.out.println(e.toString());
JOptionPane.showMessageDialog(null,"Roger:获取结果集时数据没有找到!\nSystem:"+e.toString());
return null;
}
}
public boolean executeQuery(String s1) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException e) {
System.out.println(e.toString());
JOptionPane.showMessageDialog(null,"Roger:执行查询语句时驱动无法加载!\nSystem:"+e.toString());
}
try {
Connection con1=DriverManager.getConnection("jdbc:odbc:BookManagerDB","admin","sa");
Statement stat1=con1.createStatement();
stat1.executeUpdate(s1);
con1.commit();
return true;
}catch(SQLException e) {
System.out.println(e.toString());
JOptionPane.showMessageDialog(null,"Roger:执行查询语句时数据没有找到!\nSystem:"+e.toString());
return false;
}
}
}