I.T. Discussion Community!
-Collapse +Expand
DBA
Search DBA Group:

Advanced
-Collapse +Expand DBA Store
PRESTWOODSTORE

Prestwood eMagazine

March Edition
Subscribe now! It's Free!
Enter your email:

   ► MB LobbyDBA, Databases, & Data BoardDB Other & Misc. Topic   Print This     

sql query to MS Access from Java

sql query to MS Access from Java in DB Other & Misc. topic (part of our DBA, Databases, & Data group).

Quick Search: sql query   sql query MS   Access Java  
andreazc
London, UK
Hi, I am trying to send SQL queries to MS Access 97 using Java but I only seem to get any response if I have a simple query of the form SELECT * FROM CUSTOMERS.

If I want to send something just slightly more complicated then it doesn't work, for example SELECT SURNAME FROM CUSTOMERS.

The code that I am using is:
Statement stmt = dbCon.createStatement ();
ResultSet rs = stmt.executeQuery (sqlStatement); //error occurs here
ResultSetMetaData rsmd = rs.getMetaData();

Is there a particular format that Access needs when sending a query or is this a problem with it?

Thanks
Andrea
 Posted 21 years ago (Thread Starter)
Comment Quote
About andreazc -Collapse +Expand
Visit Profile
Membership pending.
Member subscribes to this thread but email is NOT VERIFIED.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #340, 5 replies
Thread Started 12/21/2000 7:48:00 AM
View Counter=2963
Last Reply Posted 3/21/2001 1:43:00 PM)
Location=London, UK  
Joined=21 years ago   MB Posts=3  
andreazc
London, UK
Thanks for the suggestion, I hadn't thought of that. Unfortunately it didn't work.

If anyone has any bright ideas about why this won't work then they are all gratefully received.

Cheers.
 Posted 21 years ago (Thread Starter)
Comment Quote
About andreazc -Collapse +Expand
Visit Profile
Membership pending.
Member subscribes to this thread but email is NOT VERIFIED.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #349 (Level 1.1)  Reply to 340
Thread Started 12/21/2000 2:03:00 PM
View Counter=2
Location=London, UK  
Joined=21 years ago   MB Posts=3  
Most Recent Post
andreazc
London, UK
Thank you for the suggestion, the problem is now resolved.

For your information (and anyone else who reads this) the actual problem was caused by a corrupt ODBC driver as discovered when I reinstalled Office and the problem disappeared!!!

Cheers
 Posted 20 years ago (Thread Starter)
Comment Quote
About andreazc -Collapse +Expand
Visit Profile
Membership pending.
Member subscribes to this thread but email is NOT VERIFIED.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #1477 (Level 1.2)  Reply to 340
Reply Posted 3/21/2001 1:43:00 PM
Location=London, UK  
Joined=21 years ago   MB Posts=3  
Kevin
 (Inactive)
-- USA
Hi,

I have linked to a MSAccess database using Microsoft Visual J++ which as far I am away is virtually the same in Java.

Try usingthe following code:-

private ResultSet rs;
protected String querystring;

try{
// *** Load driver classes. ***
Class.forName("com.ms.jdbc.odbc.JdbcOdbcDriver");
// *** Create the connection. ***
Connection con = DriverManager.getConnection("jdbc dbc:logic");
// *** Compose the SQL statement. ***
Statement stmt = con.createStatement();
querystring="SELECT name FROM customers";
this.rs=stmt.executeQuery(this.querystring);
combobox.removeAll();
while(rs.next())
{
this.combobox.addItem(rs.getString(1));
}
rs.close();
con.close();
stmt.close();
}catch(Exception e1)
{}

I hope that code helps - that was how I connected to the MSAccess databse using a DSN.

Let me know if it helps you.

Kevin
 Posted 20 years ago
Comment Quote
About Kevin -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #1472 (Level 1.3)  Reply to 340
Reply Posted 3/21/2001 12:14:00 PM
Location=-- USA 
Joined=20 years ago   MB Posts=2  
Kevin
 (Inactive)
-- USA
sorry - the getconnection bit is:-

Connection con = DriverManager.getConnection("jdbc:odbc:logic");

sorry - i didn't realise it put a face in there....

Kevin
 Posted 20 years ago
Comment Quote
About Kevin -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #1474 (Level 1.4)  Reply to 340
Reply Posted 3/21/2001 12:51:00 PM
Location=-- USA 
Joined=20 years ago   MB Posts=2  
Daniel Fought
Prestwood IT
Home office in Fresno, CA.
This looks ok from an Access standpoint. You might try

SELECT Customers.surname
FROM Customers;

Dan Fought
Senior Programmer Analyst
Prestwood IT Solutions
http://www.prestwood.com

 Posted 21 years ago
Comment Quote
About Daniel Fought -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About Daniel Fought
Danial Fought is a senior programmer analyst with Prestwood IT where he develops custom Windows software and custom websites. When Dan is not coding for clients, he participates in this online community. Coding specialties include Paradox/ObjectPAL, MS Access, Visual Basic, and VS.Net/VB.Net.

Post ID #347 (Level 1.5)  Reply to 340
Reply Posted 12/21/2000 1:38:00 PM
Location=Home office in Fresno, CA. 
Joined=19 years ago   MB Posts=401   KB Posts=12   KB Comments=4  

Revive Thread!

Add a comment to revive this old thread and make this archived thread more useful.

Write a Comment...
Full Editor
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P123A1
Enter key:
Icon: A Post    Thread    Idea    Important!    Cool    Sad    No    Yes    Includes a Link...   
Thread #340 Counter
2963
Since 4/2/2008

Follow PrestwoodBoards on: 


©1995-2021 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech