java jsp 高手进来,(高分求助)

2025-01-01 11:05:46
推荐回答(3个)
回答1:

如果你是嵌入到jsp网页里:
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page contentType="text/html;charset=gb2312"%>
<%! Statement sta;%>
<%
String str=application.getRealPath("");
String path =str+"\\database\\data.mdb"; //path是数据库地址

String strurl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)}; DBQ="+path;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(strurl,"","");
sta = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
} catch (Exception e) {
out.println("错误:" + e.getMessage());
}
%>

回答2:

//自己参照修改以下

public class AccessConnection {

private static Connection conn = null;

private static String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=数据库文件名字.mdb";

private AccessConnection() {

}

public static Connection Conn() throws ClassNotFoundException, SQLException {
if (conn == null || conn.isClosed()) {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(url, 用户名, 密码);
}
return conn;
}
}

回答3:

给你个地址吧,其实和sql2000差不多,就是连接字符串不一样

http://tieba.baidu.com/f?kz=505257912