wood burning stoves 2.0*
The moose likes JDBC and the fly likes JDBC/ODBC DRIVER Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC/ODBC DRIVER" Watch "JDBC/ODBC DRIVER" New topic
Author

JDBC/ODBC DRIVER

tapenten
Greenhorn

Joined: Jun 04, 2001
Posts: 1
Hi Everyone,
I have a bit of a problem connecting to an access Database using JDBC/ODBC bridge. To make sure my datasource setup is right, I connected and populated the database by using an ASP code, but when I use Java to connect to the database it give an Exception error. Do I need to download a special driver? Please any help would be greatly appreciated.This the code below:
import java.io.*;
import java.lang.String;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.sql.Driver;

public class DbConnection extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException{

response.setContentType("text/html");
PrintWriter out = response.getWriter();

String cookie_dbName = "CGA-USER";
String cookie_dbValue = "TRACKER";
String db_filename = "index.jsp";

try{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException s){
out.println("JDBC class failed !!");
}

try{
Connection con = DriverManager.getConnection("jdbc dbc:tracker");

String template = "INSERT INTO Students_Tracker(cookiename, cookievalue, filename)VALUES(?,?,?)";
PreparedStatement pstmt = con.prepareStatement(template);
pstmt.setString(1,cookie_dbName);
pstmt.setString(2,cookie_dbValue);
pstmt.setString(3,db_filename);
pstmt.executeUpdate();
if(pstmt != null) pstmt.close();
if(con != null) con.close();
}catch(SQLException s){
out.println("Database attempt fail !!");
}
out.println("Database has been populated !!");
}
}
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"tapenten",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
tom_2000
Greenhorn

Joined: Jun 05, 2001
Posts: 7
I had similar error using jdbc/odbc driver to connect with a Microsoft Access database from a servlet, though it works fine as standalone java class.
Remember that MSAccess doesn't allow network access.
You need to set up an RMI object.
Go here for instructions on how to do this: http://www.objectweb.org/RmiJdbc/Access/access.html
g'luck
 
Consider Paul's rocket mass heater.
 
subject: JDBC/ODBC DRIVER
 
Similar Threads
Connecting to a database through servl
Prepares Statement : No ResultSet was produced
Url cannot be null error :(
SQL syntax error
Prepares Statement : Shared Memory error