请高手帮忙写一个对数据库操作的java小程序!求源码! 20
展开全部
public class Mdbda {
Statement stat;
Connection con = null;
//private String strConnect ="jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=E:\\sql\\ffxx.accdb;";
//类
public Mdbda() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:driver=Microsoft Access Driver (*.mdb, *.accdb);DBQ=E://sql//jxjyExam.accdb";
con = DriverManager.getConnection(url);
stat = con.createStatement();
} catch (ClassNotFoundException ex) {
System.out.println("加载驱动失败");
} catch (SQLException ex) {
Logger.getLogger(Mdbda.class.getName()).log(Level.SEVERE, null, ex);
}
}
public List getOtherDa(String where) {
List list = new ArrayList();
try {
String action = "select * from exam " + where;
ResultSet rs = null;
rs = stat.executeQuery(action);
while (rs.next()) {
String content=rs.getString("content");
list.add(content);
// System.out.println(content);
}
rs.close();
stat.close();
con.close();
} catch (SQLException ex) {
Logger.getLogger(Mdbda.class.getName()).log(Level.SEVERE, null, ex);
}
return list;
}
}
其他类中直接调用 new Mdbda().getOtherDa()就可以获取。
以上是access
Statement stat;
Connection con = null;
//private String strConnect ="jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=E:\\sql\\ffxx.accdb;";
//类
public Mdbda() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:driver=Microsoft Access Driver (*.mdb, *.accdb);DBQ=E://sql//jxjyExam.accdb";
con = DriverManager.getConnection(url);
stat = con.createStatement();
} catch (ClassNotFoundException ex) {
System.out.println("加载驱动失败");
} catch (SQLException ex) {
Logger.getLogger(Mdbda.class.getName()).log(Level.SEVERE, null, ex);
}
}
public List getOtherDa(String where) {
List list = new ArrayList();
try {
String action = "select * from exam " + where;
ResultSet rs = null;
rs = stat.executeQuery(action);
while (rs.next()) {
String content=rs.getString("content");
list.add(content);
// System.out.println(content);
}
rs.close();
stat.close();
con.close();
} catch (SQLException ex) {
Logger.getLogger(Mdbda.class.getName()).log(Level.SEVERE, null, ex);
}
return list;
}
}
其他类中直接调用 new Mdbda().getOtherDa()就可以获取。
以上是access
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询