Click to See Complete Forum and Search --> : Connection String (Access database on server)


kp2
10-23-2006, 09:52 AM
Hi. I am trying to write a simple servlet to connect to an Access database stored on a server but I am having trouble with the connection string. (keep getting dsn too long error)

All the examples I have looked at connect to a database on a local machine but I do not want this!

Any help would be greatly appreciated. :)

Khalid Ali
10-23-2006, 07:00 PM
show us the actual code u are using to connect to db..

kp2
10-24-2006, 06:04 AM
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ConnectAccess extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head></head><title>Kevin's JDBC Access</title>" +"<BODY>\n" +"<H2>Hello from the JDBC Access</H2>\n");

int i;
Connection conn = null;

// loading jdbc driver for access
try{
// System.out.println("Trying to load driver");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
} catch(Exception e) {
System.out.println(e);
}

System.out.println("loaded driver");

// connecting to database
try{
// connection string for database
conn = DriverManager.getConnection
("jdbc:odbc://mudfoot.doc.stu.mmu.ac.uk:3306/porterk?user=******&password=*******/db1.mdb");
System.out.println("Connection to database successful.");
}
catch(SQLException se) {
System.out.println(se);
}