日期:2014-05-16  浏览次数:20563 次

JDBC_ODBC连接Access数据库,不需要设置数据源

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%>
<%
?????? // JDBC_ODBC连接Access数据库,不需要设置数据源???
?????? // ******* 数据库连接代码开始? *******


??????? //异常处理语句
??????? //? try
??????? //? {?
??????? //以下几项请自行修改---------------------------------------
??????? String spath = "\\db\\main.mdb";????????????????? //Access 数据库路径
??????? String dbpath = application.getRealPath(spath);???????????? //转化成物理路径
??????? String dbname = "";??????????????????????????????????????????????????????????????? //Acvess 数据库用户名,没有则为空
??????? String user = "";?????????????????????????????????????????????????????????????????????? //Access 数据库密码,没有则为空
??????? //数据库连接字符串
??????? String url ="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+dbpath;
??????? //加载驱动程序
??????? Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
??????? //建立连接
??????? Connection conn= DriverManager.getConnection(url);
??????? //?? }catch(Exception e)
??????? //?? {
??????? //?? out.print("数据库连接错误!,错误信息如下:<br>");
??????? //?? out.print(e.getMessage());
??????? //?? String spath = "\\db\\main.mdb";//Access 数据库路径
??????? //?? String dbpath = application.getRealPath(spath);//转化成物理路径
??????? //?? out.print(dbpath);
??????? //?? }??
%>