| Author |
PreparedStatement
|
Sals Hamid
Greenhorn
Joined: Jan 04, 2002
Posts: 24
|
|
I write jdbc code in jsp file and it work fine but when i use prepared statements it creates problem.Here is the code:<%@ page language ="java" import="java.sql.*"%> <%! int id; Connection conn=null; PreparedStatement pstm=null; ResultSet rs=null; %> <table border ="1"> <tr> <td>ID</td> <td>Name</td> <td>Address</td> <td>E-Mail</td> <td>Contact</td> </tr> <% try { String idd= request.getParameter("id"); id=Integer.parseInt(idd); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn=DriverManager.getConnection("jdbc dbc:222"); PreparedStatement pstm=conn.PrepareStatement("Select * from directory where id =?"); pstm.setInt(1,id); rs=pstm.executeQuery(); while(rs.next()) { %> <tr> <td><%=rs.getInt("id")%></td> <td><%=rs.getString("Name")%></td> <td><%=rs.getString("Address")%></td> <td><%=rs.getString("E-Mail")%></td> <td><%=rs.getString("Contact")%></td> </tr> <% } }catch(Exception e){ e.printStackTrace(); } %> Whats the problem?
|
No Path of Flowers lead to glory
|
 |
Roy Ben Ami
Ranch Hand
Joined: Jan 13, 2002
Posts: 732
|
|
didnt you by accident declare preparestatement twice? here: <%! int id; Connection conn=null; PreparedStatement pstm=null; ResultSet rs=null; %> and here: PreparedStatement pstm=conn.PrepareStatement("Select * from directory where id =?"); just write in the second time: pstm=conn.prepareStatment etc..... (drop the PreparedStatement declration again) im not sure if it is the problem , but i hope it helps somehow.
|
 |
 |
|
|
subject: PreparedStatement
|
|
|