Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Meet and Greet (http://www.go4expert.com/community/meet-and-greet/)
-   -   jsp coding for access connectivity (http://www.go4expert.com/community/jsp-coding-access-connectivity-t25201/)

Mirunalini 9Mar2011 18:09

jsp coding for access connectivity
 
hi
everyone

i was trying to connect jsp pages with ms access database but while trying the following code
insertion is done successfully but update and deletion s returning the else part of it..
can anyone help me out regarding this:
<%@ page language="java" import="java.sql.*"%>
<%
Connection con = null;
Statement st = null;
ResultSet rs = null;
PreparedStatement pst = null;
int no = Integer.parseInt(request.getParameter("NO"));
String name = request.getParameter("NAME");
String address = request.getParameter("ADDRESS");
String btn = request.getParameter("btn");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:student");
st = con.createStatement();
rs = st.executeQuery("select * from student");
if (btn != null) {
if (btn.equals("Insert")) {
int k = 0;
while (rs.next()) {
if (rs.getInt(1) == no) {
k = 1;
}
}
if (k == 0) {
pst = con.prepareStatement("insert into student values (?,?,?)");
pst.setInt(1, no);
pst.setString(2, name);
pst.setString(3, address);
int i = pst.executeUpdate();
%>
<%
if (i > 0) {
out.println("record inserted succesfully");
} else {
out.println("record not inserted");
}%>
<%
} else {
out.println("record alredy exist");
}
}
else if (btn.equals("update")) {
pst = con.prepareStatement("update student set name=? ,address=? where no=?");
pst.setInt(3, no);
pst.setString(1, name);
pst.setString(2, address);
int j = pst.executeUpdate();
%>
<% if (j > 0) {
out.println("updated");
} else {
out.println("not updated");
}%>
<% }
else if (btn.equals("delete")) {
pst = con.prepareStatement("delete from student where no=?");
pst.setInt(1, no);
int l = pst.executeUpdate();%>
<%if (l > 0) {
out.println("deleted");
} else {
out.println("record not found");
}%>
<% }
else
{
out.println("not valid action");
}
}
else
{
out.println("Specify the action");
}
%>
<table border="0" bgcolor="lightgreen" cellspacing="5" cellpadding="2">
<tr><th>No</th><th>Name</th><th>Address</th></tr>
<%
st = con.createStatement();
rs = st.executeQuery("select * from student");
while (rs.next()) {
%>
<tr>
<td><%=rs.getInt(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
</tr>
<% }
%>
</table>
this s my code and i am trying this in netbeans 6.8
and using tom cat server


All times are GMT +5.5. The time now is 11:19.