Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC/ODBC DRIVER

 
tapenten
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
tom_2000
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic