Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 7th, 2005, 04:19 PM
davatar davatar is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 1 davatar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 8 sec
Reputation Power: 0
Problems connecting Access database

Please help!!
Can someone tell me what's wrong in my code? I can't connect to the database, i get the following messsage:
java.lang.NullPointerException
at javaapplication1.Main.main(Main.java:82)
Error connecting to db: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

The row (82) is:Statement st = conn.createStatement();

and the code:

Code:
try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(ClassNotFoundException e) {
			System.out.println(e.toString());
		}

   String file = "C:/Java/JavaApplication1/Some.mdb";

   
   //String url = "jdbc:odbc:Driver=MSADB;DBQ="+file;
   String url = "jdbc:odbc:Driver={Microsoft Access Driver(*.mdb)};DBQ="+file;
   
   Connection conn = null;
  try {
     conn = DriverManager.getConnection(url,"usr","psw");
conn = DriverManager.getConnection(url);
     if (conn == null)
				System.out.println("Driver failed - null Connection returned.");	
			else
				System.out.println("-- Success");

}

catch(SQLException err) {

    System.out.println("Error connecting to db: "+err.getMessage());

}

/*catch(ClassNotFoundException err) {

    System.out.println("Error creating ODBC class: "+err.getMessage());

}*/
         
         try 

{

    Statement st = conn.createStatement();
    ResultSet set = st.executeQuery("Some SQL");

Last edited by MadCowDzz : September 8th, 2005 at 07:42 AM. Reason: added [code] tags

Reply With Quote
  #2  
Old September 10th, 2005, 03:21 AM
gertcuppens's Avatar
gertcuppens gertcuppens is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 118 gertcuppens User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 28 m
Reputation Power: 5
driver failed or not ?

The only way that you get a nullpointerexception on
Code:
Statement st = conn.createStatement();


is when conn would be null. But in that case, you would have
seen "driver failed - null connection".
You do not mention this, but did your program print the line "-- success" ?

Last edited by gertcuppens : September 10th, 2005 at 03:21 AM. Reason: wrong spelling

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Problems connecting Access database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway