How to make connection to Access Database with JSP dynamically

hi

I want to make connection to access database from jsp with dynamically

but when i used following code then it is not working> is there anybody can help me?

[CODE]

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<%@ page import="java.sql.*" %>

<%@ page import="java.util.*" %>

<title>JSP Example 2</title>

</head>

<body>

<h1>JSP Example 3</h1>

<%

Connection dbcon;

ResultSet result;

PreparedStatement pstm;

String id ;

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=database/data.mdb";

dbcon=DriverManager.getConnection(url);

id = request.getParameter("Id");

pstm =dbcon.prepareStatement("select * from t_data");

result=pstm.executeQuery();

boolean value =result.next();

if (value!=false){

out.println("<table border=1>");

do{

String ID=result.getString("ID");

String name = result.getString("Name");

String city = result.getString("City");

out.println("<tr><td>" + name);

out.println("<td>" + city);

out.println("</td>");

out.println("<td>"+ID);

out.println("</td>");

out.println("</tr>");

}while(result.next());

}

out.println("</table>");

}

catch(ClassNotFoundException cnf){

out.println("Database error");

}

%>

</body>

</html>

[/CODE]

but when i use following line then then above code is working good

[CODE]

String url="jdbc:odbc:data";

[/CODE]

can anyone give me the solution.

Thanks

Bina

[2077 byte] By [bina_jatnoa] at [2007-10-2 21:50:07]
# 1
Do you have the required driver in the folder\Tomcat 5.0\common\lib
angrycata at 2007-7-14 1:05:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

The JdbcOdbcBridge is a default installation with Java. It is one of the standard sun classes.

I presume you have a SYSTEM level DSN configured in the ODBC control panels called "data"?That would explain why

"jdbc:odbc:data" data would work,

while "jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=database/data.mdb" does not.

Where does your database file reside on disk? You have given a relative reference in the URL. Relative to where? My guess would be that Tomcat is looking relative to the Tomcat/bin directory (ie current working folder)

Try specifying an absolute file path to the database as a test

ie

jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=c:/myproject/database/data.mdb

Does that work?

evnafetsa at 2007-7-14 1:05:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
hi angrycat,Thanks ur suggession. But would u give me the any link about this to solve this? THanks bina
bina_jatnoa at 2007-7-14 1:05:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Hi evnafats, thans for ur help. It is working. Could u tell me which database is better to use to make web application? Could u tell meis the MySQL better to use to make web application? Pleease help me.ThanksBina
bina_jatnoa at 2007-7-14 1:05:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

hi evnafets,

Thanks ur suggesstion. But i want to keep the database in the current working directory? For running this code i have used Tomcat5.5. When i keep database in the directory of tomcat/bin then my program is not working. So please give me the solution ? Please help me

Thanks

bina

bina_jatnoa at 2007-7-14 1:05:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...