Hi,
Im trying to run my code to access a simple DB but its giving me this error :
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:ucanaccess:\data\TestDB.accdb
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at mainProgram.Back_End.getDBData(Back_End.java:214)
at mainProgram.Back_End.main(Back_End.java:84)
Here's my code:
packagemainProgram;importjava.io.*;importjava.io.BufferedWriter;importjava.io.File;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io.FileWriter;importjava.io.IOException;importjava.sql.*;importjava.util.Scanner;importnet.ucanaccess.*;importorg.apache.commons.io.*;importcom.itextpdf.text.*;importcom.itextpdf.text.pdf.PdfPCell;importcom.itextpdf.text.pdf.PdfPTable;importcom.itextpdf.text.pdf.PdfWriter;importinterfaces.iRL;publicclassBack_End{publicstaticvoidmain(String[]args)throwsSQLException,ClassNotFoundException{getDBData();}publicstaticvoidgetDBData()throwsSQLException,ClassNotFoundException{Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");Connectionconn=DriverManager.getConnection("jdbc:ucanaccess:\\data\\TestDB.accdb");Statements;s=conn.createStatement();ResultSetrs;rs=s.executeQuery("SELECT [FirstName] FROM [Test]");System.out.println(rs.getString(1));while(rs.next()){System.out.println(rs.getString(1));}}}
Im Using Eclipse and here is where my Libraries are located and where the DB is located. https://ibb.co/cUovTR https://ibb.co/dUz28R
Note: The reason why im using "jdbc:ucanaccess:\data\TestDB.accdb" instead of "jdbc:ucanaccess://C:...\data\TestDB.accdb" is beacuse this java project is being shared over GitHub.
Last edit: Michael Schwamborn 2017-11-18
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Im trying to run my code to access a simple DB but its giving me this error :
Here's my code:
Im Using Eclipse and here is where my Libraries are located and where the DB is located.
https://ibb.co/cUovTR
https://ibb.co/dUz28R
Note: The reason why im using "jdbc:ucanaccess:\data\TestDB.accdb" instead of "jdbc:ucanaccess://C:...\data\TestDB.accdb" is beacuse this java project is being shared over GitHub.
Last edit: Michael Schwamborn 2017-11-18
The UCanAccess connection URL must always begin with
jdbc:ucanaccess://
, followed by the path to the database file.For a relative path (e.g.,
data\TestDB.accdb
) that would bejdbc:ucanaccess://data/TestDB.accdb
Last edit: Gord Thompson 2017-11-18
Ok It's working now
Thank you!