Forums Register Login

using ms-access as back end.pl hlp

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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).]
+Pie Number of slices to send: Send
Danged smilies! That should be
con = DriverManager.getConnection("jdbc:odbc:" + DSNAME);


------------------
Phil Hanna
Author of :
JSP: The Complete Reference
Instant Java Servlets
+Pie Number of slices to send: Send
You can use the edit button to go in to your post and turn off smilies.
+Pie Number of slices to send: Send
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();
}
}
}


On top of spaghetti all covered in cheese, there was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1050 times.
Similar Threads
Migrating from Ms Sql Server(T-SQL) to Oracle database 10g(PL-SQL)
Datasource for MS-Access....
JDBC - Access Connection
netbeans-odbc jar file
JSP/Servlet With MS Excel?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:47:39.