473,507 Members | 4,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to connect to MS Access database with Java 8?

10 New Member
How to connect to MS Acess Database with Java 8?

Here is the error I am getting:

Expand|Select|Wrap|Line Numbers
  1. SQLException: No suitable driver found for jdbc:ucanacess:Database11
  2.  


Here is my path for my MS Access Database that I am trying to connect:

Expand|Select|Wrap|Line Numbers
  1. C:\Users\dave\My_WorkSpace\Eclipse_Workspaces\workspace-jsp\Database11.accdb

Take A look at the attached image. It will show you what jar files I have added to my project.



and here is the code I am using to connect to database.

Expand|Select|Wrap|Line Numbers
  1. public class ex01 {
  2.     public static void main(String[] args) {
  3.         String url = "jdbc:ucanacess:Database11";
  4.  
  5.         Connection con;
  6.  
  7.         Statement stmt;
  8.  
  9.         String query = "Select * from user";
  10.  
  11.  
  12.          try
  13.           {
  14.              Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
  15.  
  16.            con = DriverManager.getConnection(url, "", "");
  17.  
  18.            stmt = con.createStatement();
  19.  
  20.            // Returns a ResultSet that contains the data produced by the query; never null
  21.            ResultSet rs = stmt.executeQuery(query);
  22.  
  23.  
  24.            System.out.println("User Data:");
  25.            System.out.println("FirstName\tLastName\tAge");
  26.  
  27.            while (rs.next())
  28.            {
  29.                String fName = rs.getString("FirstName");
  30.                String lName = rs.getString("LastName");
  31.                int age = rs.getInt("age");
  32.                System.out.println(fName + "\t" + lName + "\t" + age);
  33.            }
  34.  
  35.            stmt.close();
  36.  
  37.            con.close();
  38.           } 
  39.           catch(SQLException ex) 
  40.           {
  41.            System.err.println("SQLException: " + ex.getMessage());
  42.           }
  43.     }
  44. }
  45.  
Attached Images
File Type: png tesss.png (8.7 KB, 578 views)
Aug 2 '15 #1
3 11263
Luuk
1,047 Recognized Expert Top Contributor
The error is correct,
You have a typing error in 'ucanaccess'
Aug 2 '15 #2
gamer2d
10 New Member
Thank you so much for getting back to me so fast!

I just have fix that typo by change that line to:

Expand|Select|Wrap|Line Numbers
  1. String url = "jdbc:ucanaccess://C:/Users/dave/My_WorkSpace/Eclipse_Workspaces/workspace-jsp/Database11.accdb";
  2.  
and now I get the following error:
Expand|Select|Wrap|Line Numbers
  1. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/builder/CompareToBuilder
  2.     at com.healthmarketscience.jackcess.impl.RowIdImpl.compareTo(RowIdImpl.java:106)
  3.     at com.healthmarketscience.jackcess.impl.IndexData$Entry.compareTo(IndexData.java:2039)
  4.     at com.healthmarketscience.jackcess.impl.IndexData$Entry.compareTo(IndexData.java:1847)
  5.     at java.util.Collections.indexedBinarySearch(Unknown Source)
  6.     at java.util.Collections.binarySearch(Unknown Source)
  7.     at com.healthmarketscience.jackcess.impl.IndexData$DataPage.findEntry(IndexData.java:2570)
  8.     at com.healthmarketscience.jackcess.impl.IndexData.findEntryPosition(IndexData.java:844)
  9.     at com.healthmarketscience.jackcess.impl.IndexData.access$3700(IndexData.java:47)
  10.     at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.updatePosition(IndexData.java:2335)
  11.     at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.restorePosition(IndexData.java:2273)
  12.     at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.restorePosition(IndexData.java:2256)
  13.     at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.beforeEntry(IndexData.java:2218)
  14.     at com.healthmarketscience.jackcess.impl.IndexCursorImpl.findPotentialRow(IndexCursorImpl.java:376)
  15.     at com.healthmarketscience.jackcess.impl.IndexCursorImpl.findFirstRowByEntryImpl(IndexCursorImpl.java:282)
  16.     at com.healthmarketscience.jackcess.impl.IndexCursorImpl.findFirstRowByEntry(IndexCursorImpl.java:153)
  17.     at com.healthmarketscience.jackcess.impl.DatabaseImpl$DefaultTableFinder.findRow(DatabaseImpl.java:2074)
  18.     at com.healthmarketscience.jackcess.impl.DatabaseImpl$TableFinder.findObjectId(DatabaseImpl.java:1953)
  19.     at com.healthmarketscience.jackcess.impl.DatabaseImpl.readSystemCatalog(DatabaseImpl.java:858)
  20.     at com.healthmarketscience.jackcess.impl.DatabaseImpl.<init>(DatabaseImpl.java:518)
  21.     at com.healthmarketscience.jackcess.impl.DatabaseImpl.open(DatabaseImpl.java:389)
  22.     at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:248)
  23.     at net.ucanaccess.jdbc.DefaultJackcessOpener.open(DefaultJackcessOpener.java:38)
  24.     at net.ucanaccess.jdbc.DBReference.<init>(DBReference.java:158)
  25.     at net.ucanaccess.jdbc.DBReferenceSingleton.loadReference(DBReferenceSingleton.java:57)
  26.     at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:103)
  27.     at java.sql.DriverManager.getConnection(Unknown Source)
  28.     at java.sql.DriverManager.getConnection(Unknown Source)
  29.     at ex01.main(ex01.java:37)
  30. Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.builder.CompareToBuilder
  31.     at java.net.URLClassLoader$1.run(Unknown Source)
  32.     at java.net.URLClassLoader$1.run(Unknown Source)
  33.     at java.security.AccessController.doPrivileged(Native Method)
  34.     at java.net.URLClassLoader.findClass(Unknown Source)
  35.     at java.lang.ClassLoader.loadClass(Unknown Source)
  36.     at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
  37.     at java.lang.ClassLoader.loadClass(Unknown Source)
  38.     ... 28 more
  39.  
but if you take a look at the attached image. you can see I have all the jar files.
Aug 2 '15 #3
Luuk
1,047 Recognized Expert Top Contributor
sorry to say, but my Java skills fail at this point

But, I think, you should improve your code
change line #9 to:
Expand|Select|Wrap|Line Numbers
  1.          String query = "Select FirstName, LastName from user";
  2.  
Whenever you change your database, and i.e. drop the column 'FirstName' your query should give an error. This will not happen if you do 'select * from....', that's why I don't like the '*'
Aug 3 '15 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3548
by: Thomas Tsang | last post by:
I am using ASP + IIS + MS access, when running the following codes: set Conn=Server.CREATEOBJECT("ADODB.CONNECTION") conn.open "DRIVER={Microsoft Access Driver (*.mdb)}; " &...
7
18934
by: vigneshwaran G via DotNetMonster.com | last post by:
Hi , I am trying ot connect a VB application to Access database. iam using the following connection string : con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;data source=c:\...
1
5408
by: rajusonavane | last post by:
hi i m helpless on connect oracle or access database with xml programm plz give me sample code of program how to connect thanking you raju
0
1991
by: sandeepl | last post by:
Hi i am trying to connect a Ms access database from Oracle 8i. but getting following error. Pls help me in the same.. ERROR at line 1: ORA-28500: connection from ORACLE to a non-Oracle [ODBC...
0
1396
by: rendanime | last post by:
Hi All I have designed an Access database and now i want to connect it with Delphi 5. Can anyone help?????
0
1952
by: asad56 | last post by:
I am workin with a superstore managment project. I connect Access database with main form . Then it work properly. But now I connect same database with another table or field in another form which is...
2
1839
9815402440
by: 9815402440 | last post by:
hi i want to connect access database which is on remote server (web server). can anybody please tell how to do this? thanx in advance. manpreet singh dhillon hoshiarpur
6
5014
9815402440
by: 9815402440 | last post by:
hi i have a ms access database which is on web server (ftp://www.abc.com) . i want to connect this database using ado in vb6. please help regards manpreet singh dhillon hoshiarpur
0
1567
by: vidhyaG | last post by:
Hi, i have a database in my ftp server.and i am developing windows application using C# language.now i want to connect a database from ftp server.i tried but it did not work....so,help me... ...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.