This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

using ms-access as back end.pl hlp

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Danged smilies! That should be
con = DriverManager.getConnection("jdbc:odbc:" + DSNAME);


------------------
Phil Hanna
Author of :
JSP: The Complete Reference
Instant Java Servlets
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the edit button to go in to your post and turn off smilies.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
}
}


 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic