• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help for Access-JDBC

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Frank Wang
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Frank Wang
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic