
hai i am doing one program in jsp i want to check the jsp life cycle methods so wrote one program, in which i write jspInit() method and jspDestroy() methods. but i am getting error i crate a table with the name employee i am sending sample code to u. plz help me to fix this problem
<%@ page import ="java.sql.*" %> <%@ page import ="java.util.*" %> <%! Connection con; PreparedStatement ps; public void jspInit() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:online","system","manager"); ps=con.prepareStatement("insert into employees values(?,?,?)"); } catch(Exception e) { e.printStackTrace();
}
} public void jspDestroy() { try { ps.close(); con.close(); } catch(Exception e) { e.printStackTrace(); } } %> <%
int eno = Integer.parseInt(request.getParameter("t1")); String name=request.getParameter("t2"); float sal = Float.parseFloat(request.getParameter("t3")); ps.setInt(1,eno); ps.setString(2,name); ps.setFloat(3,sal); ps.executeUpdate(); %> <%@ include file ="emp.html" %>

JSP with access database
To set up the DSN connection, 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.
JSP 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")%></td></tr>
<%
}
rs.close();
st.close();
con.close();
}
catch(Exception e){}
%>
</table>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.