connection b/w jsp and jdbc to access database (URGENTLY REQUIRED)
hi to all,
i m a student of mca developing a website in JSP. i want to connect my database (which is in MS-access) by using JSP. can anyone give me idea how i can do this. if possible pls give me the code to connect jsp and database by which i can handle the all database operations (insert, delete , update, select, etc.). pls give me reply as early as possible
# 1
String url = "jdbc:odbc:Datasourcename";Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection(url,"","");Message was edited by: kamal_shan
# 2
Hi,
To connect the jdbc with jsp, i just use the following code in scriplets of the jsp code. Better try out with. I had used the mysql database.
<html>
<head>
<title> JSP- JDBC interaction </title>
</head>
<body>
<table border=2 cellpadding=5 cellspacing=5> <tr>
<%@ page language="java" import="java.sql.*"%>
<%
Class.forName("org.gjt.mm.mysql.Driver");//Driver for mysql in my syst
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbmaintain","root","");
Statement stm = con.createStatement();
ResultSet rs = stm.executeQuery("select * from userdetails");
while (rs.next())
{
%>
<td> <%=rs.getString(1)%> </td>
<%
}
%>
</tr>
</table>
</body>
</form>
</html>
This is what the way i work with. If you have any problem in this regards then just reply me. I will work up with the issue and come out with the solution
Thanks & Regards,
Michael
# 3
The code above probably works, but I would strongly recommend you to catch errors by using try/catch/finally.Oh, and by the way, your ResultSet isn't closed.