Home > Database > Mysql Tutorial > 用Jdbc-odbc直接连接access文件_MySQL

用Jdbc-odbc直接连接access文件_MySQL

WBOY
Release: 2016-06-01 14:10:30
Original
1069 people have browsed it

AccessJDBCODBC

  
对于设置与windows下的jsp服务器,且系统较小时,使用access是一个比较好的选择,但是要使用access数据库一般要通过数据源。这里提供一种不用使用数据源用java直接连接数据源的方法。例子程序如下:

importjava.sql.*;

publicclassAccess

{

publicstaticvoidmain(Stringargs[])

{

try

{

Stringstrurl="jdbc:odbc:driver={MicrosoftAccessDriver(*.mdb)};DBQ=books.mdb";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connectionconn=DriverManager.getConnection(strurl);

Statementstmt=conn.createStatement();

ResultSetrs=stmt.executeQuery("select*frombooks");

if(rs.next())

{

System.out.println(rs.getString("简介"));

}

}catch(Exceptione)

{

System.out.println(e);

}

}

}

可以看到只要在driver后面加上odbc驱动即可不用设置数据源,这种方法对其他小型数据库(如forpro)应该也适用。
(出处:CSDN)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template