aspose file tools*
The moose likes JDBC and the fly likes using ms-access as back end.pl hlp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "using ms-access as back end.pl hlp" Watch "using ms-access as back end.pl hlp" New topic
Author

using ms-access as back end.pl hlp

Ram Ganesh
Greenhorn

Joined: Feb 01, 2001
Posts: 11
i intend to use ms-access as backend for my jdbc. i have got access2000 installed in my machine.if any one of u can pl. send me a small java program with basic set of commands for connecting to an access database it would be of great use to me.
thnx in advance
ram ganesh
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
Here is an example of using the JDBC-ODBC bridge with a Microsoft Access database. You need to define a system data source name (DSN) first; I've defined one for the USDA nutrient database (USDA).
There is a "Getting Started" document in the JDK that is quite useful for getting up to speed on JDBC.
import java.io.*;
import java.sql.*;
import java.util.*;
public class JDBC_Sample
{
public static final String DRIVER_CLASS = "sun.jdbc.odbc.JdbcOdbcDriver";
public static final String DSNAME = "usda";
public static void main(String[] args)
throws Exception
{
new JDBC_Sample();
}
public JDBC_Sample() throws ClassNotFoundException, SQLException
{
// Load the JDBC driver class
Class.forName(DRIVER_CLASS);
// Connect to the database
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection("jdbc dbc:" + DSNAME);
stmt = con.createStatement();
// Run a query
rs = stmt.executeQuery("select * from fd_groups");
while (rs.next()) {
String code = rs.getString(1);
String description = rs.getString(2);
System.out.println(code + " " + description);
}
}
finally {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
if (con != null)
con.close();
}
}
}

------------------
Phil Hanna
Author of :
JSP: The Complete Reference
Instant Java Servlets
[This message has been edited by Thomas Paul (edited April 14, 2001).]


Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
Danged smilies! That should be
con = DriverManager.getConnection("jdbcdbc:" + DSNAME);


------------------
Phil Hanna
Author of :
JSP: The Complete Reference
Instant Java Servlets
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You can use the edit button to go in to your post and turn off smilies.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
James LX
Greenhorn

Joined: Apr 16, 2001
Posts: 1
Hi Phil,
I am running into a similar problem. I alwasy got 'ClassNotFoundException' message when I run my program. I am using the driver "sun.jdbc.odbc.JdbcOdbcDriver". Where can i find this driver?
Thanks
James

Originally posted by Phil Hanna:
Here is an example of using the JDBC-ODBC bridge with a Microsoft Access database. You need to define a system data source name (DSN) first; I've defined one for the USDA nutrient database (USDA).
There is a "Getting Started" document in the JDK that is quite useful for getting up to speed on JDBC.
import java.io.*;
import java.sql.*;
import java.util.*;
public class JDBC_Sample
{
public static final String DRIVER_CLASS = "sun.jdbc.odbc.JdbcOdbcDriver";
public static final String DSNAME = "usda";
public static void main(String[] args)
throws Exception
{
new JDBC_Sample();
}
public JDBC_Sample() throws ClassNotFoundException, SQLException
{
// Load the JDBC driver class
Class.forName(DRIVER_CLASS);
// Connect to the database
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection("jdbc dbc:" + DSNAME);
stmt = con.createStatement();
// Run a query
rs = stmt.executeQuery("select * from fd_groups");
while (rs.next()) {
String code = rs.getString(1);
String description = rs.getString(2);
System.out.println(code + " " + description);
}
}
finally {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
if (con != null)
con.close();
}
}
}

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using ms-access as back end.pl hlp
 
Similar Threads
JDBC - Access Connection
Datasource for MS-Access....
netbeans-odbc jar file
JSP/Servlet With MS Excel?
Migrating from Ms Sql Server(T-SQL) to Oracle database 10g(PL-SQL)