No suitable driver found when making SQL connection to MS Access Database in java -


I have a simple Java application in Jebton (GateDataFormDB) which assumes loading data from the database shown in the path In the code given below, in Jtable in the application.

Edit in code:

  Private Zero GetDataFromDBActionPerformed (java.awt.event.ActionEvent evt) {Connection Con; Results set rs = null; Description stmt; Try {class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); Con = DriverManager.getConnection ("jdbc: odbc: driver = {MS Access driver (* .mdb, * .accdb)} dbQ = c: \\ user \\ Bruger \\ document \ database11.accdb"); Stmt = con.createStatement (); String query = null; Query = "select * with cost"; Rs = stmt.executeQuery (query); I = 0; While (rsnext ()) {i = i + 1; JTable.getModel () SetValueAt (rs.getString (1), i, 1); JTable.getModel () SetValueAt (rs.getString (2), i, 2); } Rs.close (); Stmt.close (); con.close (); } Hold (exception mistake) {System.out.println (err.getMessage ()); }}   

When I press the button I get the following message in the Run Output window:

No suitable driver was found for jdbc: odbc: driver = {Microsoft Access Drivers ( .mdb, .accdb}}; DBQ = C: \ Users \ Bourgeois Documents \ database11.acadb

I have the top Import of my code:

  import java.sql. *;   

I change from "Microsoft Access Driver" to "MS Access Driver" Also tried, but I get the same message in the Run Output window.

Jdbc: odbc: driver = {MS Access driver ( .mdb, .accdb }} DBQ = C: \ Users \ Bruger \ Documents \ Database11.accdb No suitable driver was found

I am truly grateful for all your help, input and feedback.

dependent driver and if you are first JDK6 **!

The driver must be registered.

Try adding Switch to:

  Class.forName ( "sun.jdbc.odbc.JdbcOdbcDriver");   

Such:

  class. ForName ("sun.jdbc.odbc.JdbcOdbcDriver"); Con = DriverManager.getConnection ("jdbc: odbc: driver = {Microsoft Access driver (* .mdb, * .accdb)}; dbQ = c: \\ user \\ Bruger \\ document \ database11.accdb");   

It is also worth mentioning that whenever you get a connection, you do not have to do this, just once to ensure that the class is full.

There are a few stackwaveflow questions about this, but the reason for this is:

Source - From Java Tutorials:

In previous versions of JDBC To get a connection, you have to initialize your JDBC driver to call the class for the first time. ForName These methods require java.sql.Driver of a type of item. Each JDBC driver has one or more squares which implements the interface java.sql.Driver. ... Any JDBC 4.0 drivers that are found in your class path are automatically loaded. (However, with the standard class to load any driver manually before you JDBC 4.0.)


On the related and very important note.

I will also suggest how to handle the connection. If you are not familiar with them then external resources such as database connection and cursor are easy to leak. 'Try the blocks at the end', or see 'efforts-in-resources' in Java 7+ recently.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -