i am a newbie for java server pages and wrote a code for a jsp file which involves in jdbc connection and it gives me an error “The method resultString(int, String) is undefined for the type PreparedStatement”. Here’s my source code
<%@ page import = "java.sql.*"%>
<html>
<head>
<title>Player Details</title>
</head>
<body>
<center>
Welcome to Players Details Page
<br><br>
Player Details are
<br><br>
<table border=7>
<tr>
<td>Player No</td>
<td>Player Name</td>
<td>Country</td>
<td>Club</td>
</tr>
<%
String Player_No = request.getParameter("Player_No");
try
{
Class.forName("oracle.jdbc.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:SYSTEM/rambabu@localhost:8081:XE");
PreparedStatement ps = con.prepareStatement("Select * from Player where Player_No=?");
ps.resultString(1,Player_No);
ResultSet rs = ps.executeQuery();
if(rs.next())
{
%>
<tr>
<td><%=rs.getString(1) %></td>
<td><%=rs.getString(2) %></td>
<td><%=rs.getString(3) %></td>
<td><%=rs.getString(4) %></td>
</tr>
<%
}
rs.close();
ps.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
%>
</table>
</center>
</body>
</html>
`
there is no method named ps.resultString its public void setString(int parameterIndex,
String x)
throws SQLException
use
Once a PreparedStatement is created (prepared) for the SQL statement, you can insert parameters at the location of the question mark. This is done using the many setXXX() methods.
xxx can be String ,Int ,…
the above statement sets Player_No at the first question mark in the SQL Query. as a result SQL query will be as follow :(assuming that request.getParameter(“Player_No”) returns 5 for example)