The Artima Developer Community
Sponsored Link

Java Answers Forum
connecting to msaccess database?!

3 replies on 1 page. Most recent reply: Sep 24, 2003 2:57 PM by sandesh

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Pim Glazenborg

Posts: 1
Nickname: pim
Registered: Sep, 2003

connecting to msaccess database?! Posted: Sep 24, 2003 5:08 AM
Reply to this message Reply
Advertisement
Hello,

I am trying to connect to an access database.
The code I wrote :

String fileURL = "jdbc.odbc.dbjava";
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection(fileURL);

...


throws an exception:

java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:532)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at database.DatabaseClient.<init>(DatabaseClient.java:26)
at database.DatabaseClient.main(DatabaseClient.java:55)

Does anyone know what the problem is and how I should correct it?

Thanks!


mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: connecting to msaccess database?! Posted: Sep 24, 2003 5:42 AM
Reply to this message Reply
http://forum.java.sun.com/thread.jsp?thread=440658&forum=48&message=1985575

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: connecting to msaccess database?! Posted: Sep 24, 2003 6:19 AM
Reply to this message Reply
Your connection url is incorrect. The periods should be colons
// assuming there is an ODBC datasource named 'dbjava'
String fileURL = "jdbc:odbc:dbjava";

sandesh

Posts: 10
Nickname: sandesh
Registered: Sep, 2003

Re: connecting to msaccess database?! Posted: Sep 24, 2003 2:57 PM
Reply to this message Reply
this is what i wrote to get data from the msaccess database names northwind...
i am assuming that u did create an mdb file of the database u r trying to work on..

public static void main (String args[]) {
String url = "jdbc:odbc:Northwind";
String logInName = "user";
String password = "user";

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connect1 = DriverManager.getConnection(url,logInName,password);
DatabaseMetaData data = connect1.getMetaData();
System.out.println ("Connected to " + data.getURL());
System.out.println("Driver " + data.getDriverName());
System.out.println("Version " + data.getDriverVersion());
Statement simpleStatement = connect1.createStatement();
String query = "SELECT * FROM Employees";
ResultSet myResultSet = simpleStatement.executeQuery (query);
displayResultSet(myResultSet);
myResultSet.close();
simpleStatement.close();
connect1.close();
}

catch (SQLException e) {
}
catch (java.lang.Exception e) {
}
}
public static void displayResultSet (ResultSet myResultSet) throws SQLException {
int count;
ResultSetMetaData myData = myResultSet.getMetaData();
int numberOfColumns = myData.getColumnCount();

for (count=1; count <= numberOfColumns; count++) {
System.out.print(myData.getColumnLabel(count) + "|");
}

System.out.println();
boolean rowState = myResultSet.next();
while (rowState) {
for (count=1; count<=numberOfColumns; count++) {
System.out.print(myResultSet.getString(count) + "|");
}
System.out.println();
rowState = myResultSet.next();
}
}
}

Flat View: This topic has 3 replies on 1 page
Topic: Make a JPanel catch keypresses Previous Topic   Next Topic Topic: JDBC  Current Date

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use