爱玩科技网
您的当前位置:首页java程序连接Access数据库

java程序连接Access数据库

来源:爱玩科技网
Access数据库~~谁告诉我一个纯java的驱动程序~~来实现~~

Access数据库~~谁告诉我一个纯java的驱动程序~~来实现~~

接 Access 的java程序~~

桥接 可以打包而不用创建数据源吗??~~

Posted: 2006-06-22 21:29 | [楼 主]

angel988

用户名: ywknx 级别: 高级技术员 精华: 1 发帖: 29 经验值: 23 点 积分: 281 分 贡献值: 0

注册时间:2006-03-13 最后登录:2008-11-05

记得在一本数书里看过,俺找找看

有位高人在另一帖子里说了

1、在管理工具的数据源里新建一个数据源型设置为Access,数据源名字随便,指定mdb这个文件

把简单的事情变复杂,这就是JAV

菜鸟就是java中的门前好奇者,JAVA到底能不

Posted: 2006-06-28 12:09 |

不需要配置数据源的,只要在程序中加载了驱动程序,然后连接数据表

7-11

Posted: 2006-07-25 13:59 | 2 楼

7-11

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

String url=\"jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=\"+application.getRealPath(\"/Data/Repo\");

Connection conn = DriverManager.getConnection(url,\"\Statement stmtNew=conn.createStatement() ;

止或删除

7-26

7-14

Posted: 2006-07-27 08:59 | 3 楼

三楼,你的方法我试了+application.getRealPath编译不过去

application是什么意思 getRealPath是不是要另编写方法程序的?

cky

7-27

Posted: 2006-07-27 12:11 | 4 楼

7-27

jsp的东西

止或删除

7-26

7-14

Posted: 2006-07-27 13:49 | 5 楼

7-28

8-02

不是吧

我觉的是这样的吧

int math,physics,english,number; Connection con; Statement sql; ResultSet rs; try{

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

catch(ClassNotFoundException e) {

out.print(\"加载驱动失败!\"); } try{

con=DriverManager.getConnection(\"jdbc:odbc:haizi\\\"); sql=con.createStatement();

rs=sql.executeQuery(\"SELECT * FROM test\");

错的只要坚持就是对的,对的你不去支持也就是错的.

Posted: 2006-07-28 23:06 | 6 楼

据说不用驱动

221

7-11

Posted: 2006-08-28 16:17 | 7 楼

0-10

9-05

9-11

Get a connection by direct access

One way to get a connection is to go directly after the MS Access database file. This can be a quick y to do things, but I have seen this not work on some windows machines. Don't ask me why - I just kworks sometimes and it doesn't others...

Here is a complete sample program getting a connection to a MS Access database on my hard drive abTEST.mdb. This sample includes the lines required to set the DriverManager up for ODBC data source

import java.sql.*; class Test {

public static void main(String[] args) {

try {

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

// set this to a MS Access DB you have on your machine String filename = \"d:/java/mdbTEST.mdb\";

String database = \"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=\";

database+= filename.trim() + \";DriverID=22;READONLY=true}\"; // add on to the end // now we can get the connection from the DriverManager

Connection con = DriverManager.getConnection( database ,\"\ }

catch (Exception e) {

System.out.println(\"Error: \" + e); } } }

//save this code into a file called Test.java and compile it

Notice that this time I imported the java.sql package - this gives us usage of the java.sql.Connection ob

The line that we are interested in here is the line

Connection con = DriverManager.getConnection( database ,\"\

What we are trying to do is get a Connection object (named con) to be built for us by the DriverManagable database is the URL to the ODBC data source, and the two sets of empty quotes (\"\indicate tnot using a username or password.

In order to have this program run successfully, you have to have an MS Access database located at fion. Edit this line of code and set it to a valid MS Access database on your machine. If you do not alrn MS Access database, please jump down to Set the Access Database up as an ODBC DSN section, how to create an empty MS Access database.

If you do have a MS Access database, and this is working correctly, then you're ready to Run an SQL

2 Set up a DSN and get a connection through that

Microsoft has provided a method to build a quick Jet-Engine database on your computer without the nepecific database software (it comes standard with Windows). Using this method, we can even create a oft Access database without having MS Access installed!

As we learned earlier, MS Access data bases can be connected to via ODBC. Instead of accessing therectly, we can access it via a Data Source Name (DSN). Here's how to set up a DSN on your system

Open Windows' ODBC Data Source Administrator as follows:

In Windows 95, 98, or NT, choose Start > Settings > Control Panel, then double-click the ODBC Data n. Depending on your system, the icon could also be called ODBC or 32bit ODBC.

In Windows 2000, choose Start > Settings > Control Panel > Administrative Tools > Data Sources. In the ODBC Data Source Administrator dialog box, click the System DSN tab. Click Add to add a new DSN to the list.

Scroll down and select the Microsoft Access (.MDB) driver

Type in the name \"mdbTEST\" (no quotes, but leave the cases the same) for the Data Source Name Click CREATE and select a file to save the database to (I chose \"d:\\java\\mdbTEST.mdb\") - this createsk MS Access database! Click \"ok\" all the way out

Now our data source is done! Here's a complete program showing how to access your new DSN data

import java.sql.*; public class Test {

public static void main(String[] args) {

// change this to whatever your DSN is String dataSourceName = \"mdbTEST\";

String dbURL = \"jdbc:odbc:\" + dataSourceName; try {

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

Connection con = DriverManager.getConnection(dbURL, \"\ }

catch (Exception err) {

System.out.println( \"Error: \" + err ); } } }

//save this code into a file called Test.java and compile it

As stated in the code, modify the variable dataSourceName to whatever you named your DSN in step e.

If this complies and runs successfully, it should produce no output. If you get an error, something isn't - give it another shot!

Once this is working correctly, then you're ready to Run an SQL Statement!

Posted: 2006-09-05 23:54 | 8 楼

83

5-19

1-04

String database = \"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=\";

database+= filename.trim() + \";DriverID=22;READONLY=true}\"; // add on to the end // now we can get the connection from the DriverManager

Connection con = DriverManager.getConnection( database ,\"\ }

这种我倒是真的没有去体验过。

不过我还真的需要说用ACESS数据库,然后不用配数据源, 也就是说直接用驱动。像用SQL JDBC的那三个驱动那样。 很方便。

比如说我在网上找到了个免费空间。支持JSP的。

但我要用数据库。这些我就不能用数据源了。因为没有办法到它服务器上建数据源。 所以只能说用驱动。 。。。。。

J2EE技术交流:

MSN:langhua983@hotmail.com

QQ群:14395658

Posted: 2006-09-10 00:03 | 9 楼

因篇幅问题不能全部显示,请点此查看更多更全内容