Netbeans Database Connectivity Issue

SYNERGY

Executive Member
Joined
Jul 13, 2007
Messages
6,050
Reaction score
331
Location
Durban
http://mybroadband.co.za/vb/showthr...base-Connectivity-Issue?p=9264788#post9264788

Hi

Can anyone assist with this?

Thanks!

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.
 
Hi SYNERGY

Please check my example. Tip - Put your mdb file in the root project folder (where your manifest and build files are)
Copy the code excatly.Test - and let me know. Good luck :-)

private void accessDatabase(){

try
{Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");}
catch (ClassNotFoundException c)
{JOptionPane.showMessageDialog(this,"Database Driver Error.","Fatal Error",JOptionPane.ERROR_MESSAGE);
}

try{
String dataSourceName= "./StarWars.mdb";
String database= "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database +=database + dataSourceName.trim () + ";DriverID=22}";
connect = DriverManager.getConnection(database);
System.out.println("Connected");}
catch (Exception e)
{JOptionPane.showMessageDialog(this, "Database Connection Error ","Fatal Error",JOptionPane.ERROR_MESSAGE);
}
}
 
A more detailed example. This is the start of my form.

package yourPackageNameHere;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class yourClassHere extends javax.swing.JPanel {

public yourClassHere () {
initComponents();
accessDatabase();
}

//Variables
Connection connect = null;
Statement state = null;
ResultSet results = null;

//Connect to the database
private void accessDatabase(){

try
{Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");}
catch (ClassNotFoundException c)
{JOptionPane.showMessageDialog(this,"Database Driver Error.","Fatal Error",JOptionPane.ERROR_MESSAGE);
}

try{
String dataSourceName= "./StarWars.mdb";
String database= "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database +=database + dataSourceName.trim () + ";DriverID=22}";
connect = DriverManager.getConnection(database);
System.out.println("Connected");}
catch (Exception e)
{JOptionPane.showMessageDialog(this, "Database Connection Error ","Fatal Error",JOptionPane.ERROR_MESSAGE);
}
}
 
Hey SYNERGY
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
 
Sorry for the late response.

Yep, my bro's project. Turned out he had 32 bit JDK -.-

Thanks for all the responses! :)
 
Top
Sign up to the MyBroadband newsletter
X