Forums Register Login

Help for Access-JDBC

+Pie Number of slices to send: Send
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("jdbc:odbc: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).]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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).]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1030 times.
Similar Threads
The specified DSN contains an architecture mismatch between the Driver and Application
JDBC connectivity problem through JSP
Reading an Excel file using Java
Cannot create a new table
error when i run the program
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:35:25.