Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 18th, 2004, 07:36 PM
zombie_man23 zombie_man23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 22 zombie_man23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 16 m
Reputation Power: 0
Exclamation Java connection with MS Access

I can not get my connection string to connect to MS Access using java. Here is what I have.

try
{
// Load the Driver class file
String chemin = "e:\StudentDatabase.mdb";
String fullConnectionString = "jdbc: odbc: Driver={Microsoft Access Driver (*.mdb)};DBQ="
+ chemin;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// con = getConnection(fullConnectionString);
con = DriverManager.getConnection(fullConnectionString);

Thanks for any and all help!!!

Reply With Quote
  #2  
Old November 22nd, 2004, 02:43 AM
gertcuppens's Avatar
gertcuppens gertcuppens is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 118 gertcuppens User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 28 m 17 sec
Reputation Power: 15
Since you're using a try - catch, I suppose you are catching the different errors that can
occur. What error does your code throw back to you ?

Reply With Quote
  #3  
Old November 23rd, 2004, 04:00 PM
zombie_man23 zombie_man23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 22 zombie_man23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 16 m
Reputation Power: 0
I am using JDeveloper to create this project. I have updated the code from my origional post. Here is my new code:

try
{
// Load the Driver class file
String chemin = "e:\\CPT350\\SemesterProject\\StudentDatabase.mdb";
String fullConnectionString = "jdbc: odbc: driver={Microsoft Access Driver (*.mdb)};DBQ="
+ chemin;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// con = getConnection(fullConnectionString);
con = DriverManager.getConnection(fullConnectionString);
// Create the statement
stmt = con.createStatement();
}
catch (SQLException s) {}
try {
Statement stmt = connection.CreateStatement();

// Prepare a statement to insert a record
String sql = "INSERT INTO Student (FirstName, MiddleInitial, LastName, Email, CollegeID, ContactNumber ) VALUES('txtFirstName', 'txtMiddleInitial', 'txtLastName', 'txtEmail', 'txtCollegeID', 'txtContactNumber') )";

// Execute the insert statement
stmt.executeUpdate(sql);
} catch (SQLException s) {}
}

When I run the debugger I get two errors.

1) unreported exception: java.lang.ClassNotFountException; must be caught or delcared to be thrown.
This is the line of code it takes me too:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

2) varialbe conneciton not found in class mypackage1.StudentDataFrame
This is the line of code it takes me too:
Statement stmt = connection.CreateStatement();

Thanks for your help!

Reply With Quote
  #4  
Old November 24th, 2004, 07:57 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
What do your import statements look like?

Sounds like you forgot to import a class.

Perhaps: Statement stmt = connection.CreateStatement();
Would be better written as: Statement stmt = con.CreateStatement();

I'd also suggest putting a meaningful error in your catch's... like System.out.println(s.getMessage());
Also, make sure you catch the general exception (Exception) as well as the SQLException.

Code:
try {
   ....
}
catch (SQLException se) {
   System.out.println(se.getMessage());
}
catch (Exception e) {
    System.out.println(e.getMessage());
}

Reply With Quote
  #5  
Old November 29th, 2004, 09:57 AM
zombie_man23 zombie_man23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 22 zombie_man23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 16 m
Reputation Power: 0
here are my import statement

package mypackage1;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.BorderFactory;
import javax.swing.border.BevelBorder;
import javax.swing.SwingConstants;
import java.lang.ClassLoader;
import java.net.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;

Reply With Quote
  #6  
Old November 30th, 2004, 03:24 PM
zombie_man23 zombie_man23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 22 zombie_man23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 16 m
Reputation Power: 0
I believe I have figured it out. Or at least I don't recieve any errors when I run the debugger.

Thanks for the help!

Reply With Quote
  #7  
Old December 2nd, 2004, 10:06 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
Any idea what the problem was?

Reply With Quote
  #8  
Old December 4th, 2004, 08:41 AM
zombie_man23 zombie_man23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 22 zombie_man23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 16 m
Reputation Power: 0
not a clue

i don't have a clue. i placed my connection string directly one of the classes i was going to use it. i hard coded some sql and it worked. so i moved the connection string back to the connection class and called it from another class. and it worked.
thanks for you help!!!!

Reply With Quote
  #9  
Old December 22nd, 2004, 01:09 AM
rrreddy_1976 rrreddy_1976 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 1 rrreddy_1976 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post JDBC Error for accessing MSAccess

When I compile the following Code ..I am getting an error
unreported exception java.lang.ClassNotFoundException;must be caught or declared to be thrown
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Please tell me what is the problem in that Code
import java.sql.*;
public class Test
{
public static void main(String[] args)
{
try {
String path,fullstring;
path="C:/Program Files/Microsoft Visual Studio/VB98/BIBILO.mdb";
fullstring="jdbc: odbc: Driver={Microsoft Access Driver (*.mdb)};DBQ=" +path;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(fullstring);
System.out.println("Connected");
}catch(SQLException e){ System.err.println(e.getMessage());}
}
}

Reply With Quote
  #10  
Old December 22nd, 2004, 08:50 PM
Cookies Cookies is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: 10th Floor, Melbourne
Posts: 1 Cookies User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
First post :o

Hey, if it helps this is what i used when i wanted to connect to access, where connection data is the address of the db.

sorry about the indents but its straight out of the cvs.

Code:
  
  	private Connection conDatabase;
  	private Statement qryDatabase;
  	private ResultSet rsDatabase;
  
  
  			//open connection to database
 			/* set up DriverManager to let it know we want to communicate with
 			 ODBC data sources. Calling the static forName() method of the Class class*/
  			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  			
  			// set this to connection string to the database
  			
 			sURL = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
 			sURL += getConnectionData().trim() + ";DriverID=22;READONLY=true}";
  			System.out.println("url: "+sURL);
  			
 			// create connection to database using connection string
 			conDatabase = DriverManager.getConnection(sURL, "", "");
  			
  			 // setup java.sql.Statement to run queries
 			qryDatabase = conDatabase.createStatement();	
  
  

Reply With Quote
  #11  
Old December 30th, 2004, 07:06 PM
Tj1204 Tj1204 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 1 Tj1204 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Dsn

Why you don't just use with User Data Source?

Reply With Quote
  #12  
Old February 8th, 2005, 08:04 AM
vamshi_cm vamshi_cm is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 1 vamshi_cm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 55 sec
Reputation Power: 0
Send a message via MSN to vamshi_cm Send a message via Yahoo to vamshi_cm
I am getting an error using ur answer

Hello Reddy I am Vamshi. I have seen ur code ad tried but I am getting an error with that The Error is like No Suitable Driver Found.

SO if u dont mind can ube clear in ur answer this time
thanks


Quote:
Originally Posted by rrreddy_1976
When I compile the following Code ..I am getting an error
unreported exception java.lang.ClassNotFoundException;must be caught or declared to be thrown
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Please tell me what is the problem in that Code
import java.sql.*;
public class Test
{
public static void main(String[] args)
{
try {
String path,fullstring;
path="C:/Program Files/Microsoft Visual Studio/VB98/BIBILO.mdb";
fullstring="jdbc: odbc: Driver={Microsoft Access Driver (*.mdb)};DBQ=" +path;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(fullstring);
System.out.println("Connected");
}catch(SQLException e){ System.err.println(e.getMessage());}
}
}

Reply With Quote
  #13  
Old February 9th, 2005, 10:44 AM
gertcuppens's Avatar
gertcuppens gertcuppens is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 118 gertcuppens User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 28 m 17 sec
Reputation Power: 15
In your code you write class.forName().

I've checked my code :
Code:
 
try
   {
   Class.forName("com.mysql.jdbc.Driver").newInstance();
   resBundle = ResourceBundle.getBundle("gcoConfig");
	String dbConnectie = resBundle.getString("databaseconnection");
   dbconn = DriverManager.getConnection(dbConnectie,"gert", "sesam");
	 } catch (InstantiationException e)
Don't mind the ResourceBundle ; this is a way to put the connection string in a text
file instead of directly in the code. But the difference is I've added the method newInstance().
Perhaps this might do the trick.

Reply With Quote
  #14  
Old April 13th, 2010, 06:38 AM
mukulrocks mukulrocks is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2010
Posts: 1 mukulrocks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 21 sec
Reputation Power: 0
In This statement

jdbc: odbc: Driver={Microsoft Access Driver (*.mdb)};DBQ=" +path


Whats does Path Imply???

Which path need to be specified

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Java connection with MS Access


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap