Netbeans Database Connectivity Issue

Muhammad.R1

Active Member
Joined
Sep 8, 2007
Messages
67
Reaction score
1
Hey guys

When i run by Netbeans project, i get the following error:
"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"

The thing is im running Netbeans 7.2 at home but on my school computer (which is running 6.9),when I run the project... It works fine and database connection succeeds!

Could anyone tell me what is wrong with it?

I've done all thats required such as saving my database as a 2002-2003 format .mdb and the correct coding in my connect.java class.

Thanks

P.S The coding that works on 6.9 but not on 7.2 is located below:

Code:
 import java.sql.*; 
 import java.util.Scanner; 
 import java.io.*; 
 import javax.swing.ImageIcon; 
 public class Connect 
 { 
     Connection conn; 
     Scanner kb = new Scanner (System.in);    
     public Connect() 
       { 
       //load the driver 
          try 
          { 
             Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); 
             System.out.println ("Driver successfully loaded"); 
          } 
              catch (ClassNotFoundException e) 
             { 
                System.out.println (e.getMessage()); 
             } 


       //connect to the database 
          try 
          { 
             String filename = "StarWars.mdb"; 

             String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb,*.accdb)};DBQ="; 
             database += filename.trim () + ";DriverID=22;READONLY=true}"; 
             conn = DriverManager.getConnection (database, "", ""); 
             System.out.println ("Connection to database successfully established"); 

          } 
              catch(Exception e) 
             { 
                System.out.println (e.getMessage()); 
             } 
       }

UPDATE: I've installed Netbeans on my laptop and after running it,my project ran fine.
My computer is still new so i assume that theres some application or drivers i'm missing since its working on all computers except mine.. I have the latest JRE , drivers for hardware and Framework.
 
Last edited:
Do you have Access installed, seeing as it's looking for a driver to connect to the Access database.
 
Do you have Access installed, seeing as it's looking for a driver to connect to the Access database.

Yes i do but its access 2010 pro.
Could it be due to the version of access?
Because the school computers have 2003 and my laptop has 2007.
 
Yes i do but its access 2010 pro.
Could it be due to the version of access?
Because the school computers have 2003 and my laptop has 2007.

Shall I hazard a guess and say that its PAT time ? :)

Yeah, the 2010 versions of Office have a problem when doing the JDBC ODBC connection. Actually, I know of a friend of mine who had a problem doing the actual SQLs in his PAT because of Office 2007. He had to do prepared statements (I don't know how those work).

Simplest option is just to use 2003. I suspect that the drivers used in 2010 don't correspond with the coding involved with the direct connection.
 
Hey Muhammad.R1
If the above didn't work try this:

Are you by any chance running 64 bit windows at home and 32 bit at school?
The problem comes from the JDK that netbeans is pointing to.
The code you're using to connect to the database is from the 32 bit JDK, but if netbeans is pointing to the 64 (most likely if you're running 64 bit windows) then it wont be able to work correctly.

To fix all you need to do is download and install the java 32 bit JDK, then in netbeans right click on your project name, hover over set configuration and click customize, once there go to libraries, then at the top where it says "java platforms", click manage platforms, click add platform, search for where you installed the 32 bit jdk, select it, then exit and your project file should work correctly :)
 
Hey Muhammad.R1
If the above didn't work try this:

Are you by any chance running 64 bit windows at home and 32 bit at school?
The problem comes from the JDK that netbeans is pointing to.
The code you're using to connect to the database is from the 32 bit JDK, but if netbeans is pointing to the 64 (most likely if you're running 64 bit windows) then it wont be able to work correctly.

To fix all you need to do is download and install the java 32 bit JDK, then in netbeans right click on your project name, hover over set configuration and click customize, once there go to libraries, then at the top where it says "java platforms", click manage platforms, click add platform, search for where you installed the 32 bit jdk, select it, then exit and your project file should work correctly :)

Thank you very much!
I did everything that you said and it started working =D.
Guess it was a stupid mistake on my end lol forgetting the school computers were 32 bit :(.

There was no problem with access, i installed 07 to see if there was any difference and there was none. So it never caused the problem.. It was that stupid bit mix up!

Thanks again mate :) You saved me!!
 
Top
Sign up to the MyBroadband newsletter
X