Hi all, I have an Access database and jdk 1.3. I want to query my database through a jsp page using beans. what I need to connect to my database? any separate installation is required in order to use jdbc? Regards, mac.
no seperate installation as long as u r willing to use jdbc.odbc.JdbcOdbcDriver u need to import java.sql package and load sun.jdbc.odbc.JdbcOdbcDriver using Class.forName()
Jimi Rock
Ranch Hand
Joined: Feb 19, 2001
Posts: 134
posted
0
Hi, thanks for reply. can u provide me with the segment of code that will do the connection part? Regards. mac.
try { // Load the driver class Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Define the data source for the driver String sourceURL = "jdbc dbc:yourDataSourceName"; // Create a connection through the DriverManager Connection databaseConnection = DriverManager.getConnection(sourceURL); } catch(ClassNotFoundException cnfe) { System.err.println(cnfe); } catch(SQLException sqle) { System.err.println(sqle); } }
------------------ Bosun
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Jimi Rock
Ranch Hand
Joined: Feb 19, 2001
Posts: 134
posted
0
Hi Bosun, thanks a lot for ur reply... I have tried the code but have the following error: "Data source name not found and no default driver specified" this is may be becauae my connection url. I want to connect to an access database using jsp. servlet engine is tomcat. what to do then? Thanks in advance, mac.
U have to connect the database with ur frontend through Jdbc/Odbc driver.. and for that u have to use ODBC and connect through System DSN.. Pranit..
Originally posted by Jimi Rock: Hi Bosun, thanks a lot for ur reply... I have tried the code but have the following error: "Data source name not found and no default driver specified" this is may be becauae my connection url. I want to connect to an access database using jsp. servlet engine is tomcat. what to do then? Thanks in advance, mac.
Jimi Rock
Ranch Hand
Joined: Feb 19, 2001
Posts: 134
posted
0
Hi Pranit, can u tell plz how to connect to system DSN? Thanks.
Pranit Saha
Ranch Hand
Joined: Sep 09, 2001
Posts: 130
posted
0
Assuming that u r using Windows.. Go to start->settings->control panel->ODBC drivers->click on system DSN.. and follow the steps as it says.. tell me if u face ne prob Pranit..
Jimi Rock
Ranch Hand
Joined: Feb 19, 2001
Posts: 134
posted
0
Hi Pranit, finally I have got it... saying "Thank you" cannot express my appreciation... Regards, mac.
Pranit Saha
Ranch Hand
Joined: Sep 09, 2001
Posts: 130
posted
0
It's nice to hear that u've solved ur prob.. U r always welcome.. Pranit..
Originally posted by Jimi Rock: Hi Pranit, finally I have got it... saying "Thank you" cannot express my appreciation... Regards, mac.