how to connect to MS access database in JSP?

how to connect to MS access database in JSP? Any seetings/drivers need to be set or installed before it? Please tell what needs to be done after creating a table with an example.

View Answers

December 23, 2010 at 11:33 AM

Hello Friend,

Follow these steps:

1)Go to the start<<Control Panel<<Administrative Tools<< data sources.

2)Click Add button and select the driver Microsoft Access Driver(*.mdb).

3)After selecting the driver, click finish button.

4)Then give Data Source Name and click ok button.

5)Your DSN will get created.

6) Restart your server and run your jsp code.

Here is your required code:

<%@page import="java.sql.*"%>
<table border=1>
<tr><th>Name</th><th>Address</th></tr>

<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:student");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from data");
while(rs.next()){
    %>
<tr><td><%=rs.getString("name")%></td><td><%=rs.getString("address")%></t

d></tr>
<%
}
rs.close();
st.close();
con.close();
}
catch(Exception e){}
%>
</table>

where student is our DSN.

Thanks


March 25, 2012 at 8:52 AM

hi friend thanks a lot for the code. its working .









Related Tutorials/Questions & Answers:
Advertisements