当前位置: 技术问答>java相关
我用jsp连接access,各位高手能帖出代码给小弟,多谢!
来源: 互联网 发布时间:2015-06-26
本文导语: 我用jsp连接access2000,各位高手能帖出代码给小弟,多谢! | package test; import java.sql.*; public class bbsreg{ String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; String sConnStr = "jdbc:odbc:bbs"; Connection conn =...
我用jsp连接access2000,各位高手能帖出代码给小弟,多谢!
|
package test;
import java.sql.*;
public class bbsreg{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:bbs";
Connection conn = null;
ResultSet rs = null;
public bbsreg() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("bbsreg(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
System.err.println("aq.executeQuerystrSQL: " + sql);
}
return rs;
}
public void executeUpdate(String sql) {
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeUpdate: " + ex.getMessage());
System.err.println("aq.executeUpadatestrSQL: " + sql);
}
}
}
import java.sql.*;
public class bbsreg{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:bbs";
Connection conn = null;
ResultSet rs = null;
public bbsreg() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("bbsreg(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
System.err.println("aq.executeQuerystrSQL: " + sql);
}
return rs;
}
public void executeUpdate(String sql) {
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeUpdate: " + ex.getMessage());
System.err.println("aq.executeUpadatestrSQL: " + sql);
}
}
}
|
如上。
|
要做一个叫bbs的dsn
在你要链接数据库的jsp中加上这句:
在你要链接数据库的jsp中加上这句:
|
M$ 出access的jdbc Driver了吗?没有吧!
可以这样写jdbc url:
String strConnStr = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+request.getRealPath("access.mdb");
可以这样写jdbc url:
String strConnStr = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+request.getRealPath("access.mdb");