java - Can't connect to MS access database -
I have taken IT project home to finish school and although I can connect to your database in school I , I can not connect to it. It's on my own computer. I've changed the directory in the database class and I'm almost 100% sure the directory is right. It always gives me this error:
Driver unable to connect successfully loaded: [Microsoft] [ODBC Driver Manager] did not get the name of the data source and specify a default driver not been java.sql.SQLException: [Microsoft] [ODBC driver Manager] did not get the name of the data source and no default driver sun.jdbc.odbc.JdbcOdbc.createSQLException (JdbcOdbc.java:6964) sun.jdbc.odbc.JdbcOdbc Sun.jdbc.odbc.JdbcOdbc.SQLDriverCon specified in .standardError (JdbcOdbc.java:7121) Java.sql.DriverManager.getConnection at sun.jdbc.odbc.JdbcOdbcDriver.connect (JdbcOdbcDriver.java:174)) on nect (JdbcOdbc.java3080) sun.jdbc.odbc.JdbcOdbcConnection.initialize (JdbcOdbcConnection.java:323) DriverManager.java T7171) on java.sql.DriverManager.getConnection (DriverManager.java .33) database. (Database.java35) at GUI. (GUI.java:33) GUI $ 41.run (GUI.java less64) on java.awt.event.InvocationEvent.dispatch (InvocationEvent.java:251) on java.awt.EventQueue.dispatchEventImpl (EventQueue.java:73 ) 3) $ 3.run (EventQueue.java:694) on java.awt.EventQueue $ 3.run (EventQueue on java.awt.EventQueue $ 200 (EventQueue.java:103) on java.awt.EventQueue.access. Java: 692) java.awt.EventDispatchThread at java.security.ProtectionDomain $ 1.doIntersectionPrivilege (ProtectionDomain.java:76) java.awt.EventQueue.dispatchEvent at (EventQueue.java:703) java.security.AccessController.doPrivileged ( Native Method) on Java.awt.EventDispatchThread.pumpEventsForHierarchy (java.awt.EventDispatchThread.pumpEventsForFileer) on Java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:150) on pumpOneEventForFilters (Event DispatchThread.java table 42) (EventDispatchThread. Java: java.awt.EventDispatchThread.pumpEvents at 146) (EventDispatchThread.java:138 on java.awt.EventDispatchThread.run) (EventDispatchThread.java:91)
Here is my database code
public class database {personal fixed final string driver = "sun.jdbc.odbc.jdbcOdbcDriver"; Private Static Final string URL = "JDBC: ODBC: Driver = {Microsoft Access Driver (* .mdb, * .acadb)} dbk = c: \\ user \\ my-PC \\ documents \ netban process \\ motorbikepap \ \ MotorBikeApp \\ Database \\ Database1.accdb "; Private connection connection; Statement of personal statement; As a result of personal results result; Public database () {try {class.forName (driver); System.out.println ("The driver is loaded successfully"); } Grip (Klassnotfound Exception C) {System.out.println ("unable to load driver"); } Try {Connection = DriverManager.getConnection (url); System.out.println ("Connection successful"); } Hold (exception e) {System.out.println ("Unable to connect:" + e.getMessage ()); E.printStackTrace (); }}}
When I try to create a new instance of the database in my GUI class, I get an error. I use the following code to do this.
database db = new database (); I have solved the problem by downloading and installing the 2010 MS Access Database Engine. I
Comments
Post a Comment