开发者

problems in connecting java with ms access

hye all..

i am currently doing my fina开发者_C百科l year project in java.i want to connect a ms access database using java.But sadly i'm using windows 7 starter that cannot support odbc.do you have any idea i can solve this problem?thank for all your coming idea and help =)


Simply try to have another OS get installed or try to have some of the drivers that support JDBC and you will surely able to work in connecting dtabase with java.


You could try JDBC drivers like these:

http://www.csv-jdbc.com/stels_mdb_jdbc.htm

http://www.hxtt.com/access.html

Both are commercial products.

A free option would be to migrate the database to SQL Server Express and then use the SQL Server JDBC drivers to connect to that.


I used the sun.jdbc.odbc.JdbcOdbcDriver to connect to a MS Access database. Have that in the same directory as the class file and it should work. Although it should come already installed in the Java SDK.

This is a sample of a practice program I made a while ago.

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

System.out.println("Driver loaded");

// Establish a connection
Connection connection = DriverManager.getConnection
("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=(MS ACCESS DATABASE DIRECTORY)");

System.out.println("Database connected");

// Create a statement
Statement statement = connection.createStatement();

// Execute a statement
ResultSet resultSet = statement.executeQuery
  ("select f_name, l_name from Test where f_name = 'Luke'"); // For example

// Iterate through the result and print the results
while (resultSet.next())
  System.out.println(resultSet.getString(1) + "\t" + resultSet.getString(2) );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜