File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Help for Access-JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Help for Access-JDBC" Watch "Help for Access-JDBC" New topic
Author

Help for Access-JDBC

Frank Wang
Greenhorn

Joined: Aug 18, 2000
Posts: 25
Hi, Folks, I started to learn how to use JDBC recently. Now I got a difficulty to connect
my Access database. I have Access in my computer which runs NT. I know I need to use
JDBC.ODBC to get connection in the following coding. But when I execute the class, I get
an exception: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found
and no default driver specified.

What should I do? Is the classpath or the ODBC Data Source Manager in the Control Panel?
And how to do it?
Thank you very much. I really appreciate your help.
Frank
import java.sql.*;
public class Example1 {
��
public static void main (String args[]) {
����
try {
������
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
����
}
����
catch (Exception e) {
������
System.out.println("JDBC-ODBC driver failed to load.");
������
return;
����
}
����

try {
������
Connection conn = DriverManager.getConnection("jdbcdbc:inventory","","");
������
Statement stmt = conn.createStatement();
������
ResultSet rs = stmt.executeQuery("SELECT * FROM inventory ORDER BY price");
������
ResultSetMetaData rsmd = rs.getMetaData();
������
int numberOfColumns = rsmd.getColumnCount();
������
int rowCount = 1;
������
while (rs.next()) {
��������
for (int i=1; i<=numberOfColumns; i++) {
����������
System.out.println(rs.getString(i) + " ");
��������
}
��������
System.out.println("");
��������
rowCount++;
������
}
������
stmt.close();
����
}
����
catch (Exception e) {
������
System.out.println(e);
����
}
��
}
}

[This message has been edited by Thomas Paul (edited January 04, 2001).]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
What it is telling you is that "inventory" has not been configured in the ODBC driver under control panel. So go there and add the datasource. It is fairly straight forward.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Frank Wang
Greenhorn

Joined: Aug 18, 2000
Posts: 25
Thank you, Thomas.
I followed your instruction to try to set up the odbc data source manager, but I didn't make the program done. I know the problem is that I don't know how set it up properly. Should I set up the User DSN or the System DSN, since I have added the driver there already. No matter I set the User DSN or the System DSN with the Access Driver, I still get the same exception.
Looks like a stupid question. But I really need some hints to get the program go.
Kindly thank you, Thomas and other guys.
Frank W.
paul sun
Greenhorn

Joined: Dec 22, 2000
Posts: 28
1.
mkdir \mydb
save your database file (eg. testdb.mdb) to the \mydb directory.
Make sure the file is saved with the appropriate file extension.
2.
From Windows 95/NT 4.0:
Bring up Control Panel
Select the Start button
Select the Settings menu item
Select the Control Panel menu item
Find and double-click on the ODBC Icon (32-bit/with 32 on it). This brings up the 'Data Sources' window.
Select Add. This brings up the Add Data Source window.
Select the driver for the type of driver you want.
Setup window appears.
Name the data source "mage" (this will be your datasource name in connection url).
Fill in a description.
Click on the Select button to bring up a file dialog.
Locate the directory created in 1.
Select OK to accept new driver.
The above is adopted from a jdbc tutorial. The user dsn or system dsn doesn't matter. System dsn is available for the system which means everyone or resources using the system can access the database; user dsn is available for only the user.
[This message has been edited by paul sun (edited January 04, 2001).]
[This message has been edited by paul sun (edited January 04, 2001).]
ryan headley
Ranch Hand

Joined: Jun 28, 2000
Posts: 156
I too was having a problem with connecting to an Access database. I setup my db in Access, then configured ODBC source. I am positive all that is correct. My code compiles fine but the I get an error when it tries to connect to the DB. I used the COFFEES example from the JDBC tutorial on Suns website. The only difference being is that I created the tables with MS Access 97.
I have a post about this in the forum already. Check out that post for the error.
http://www.javaranch.com/ubb/Forum3/HTML/000397.html


Ryan Headley<br /><a href="http://www.sudovi.com" target="_blank" rel="nofollow">http://www.sudovi.com</a>
Frank Wang
Greenhorn

Joined: Aug 18, 2000
Posts: 25
Thank you very much, Paul and Ryan. I made the program go just as following your guides.
Best wishes and warmest greetings to you, Thomas and all the other guys in the new year.
Frank W.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help for Access-JDBC
 
Similar Threads
Cannot create a new table
JDBC connectivity problem through JSP
error when i run the program
Reading an Excel file using Java
The specified DSN contains an architecture mismatch between the Driver and Application