
I wrote the code as shown below, i am getting the error like "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1" my code is
<%
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/voting","root","");
PreparedStatement pst=con.prepareStatement("select * from election");
ResultSet rs=pst.executeQuery();
int i=1;
String pname="";%>
<h1 align="center">DELETE LEADER</h1>
<form action="deleteaction.jsp" method="get">
<table border="1">
<%
while(rs.next())
{
%>
<tr>
<td><%pname=rs.getString(1);%></td>
</tr>
<%
PreparedStatement pst1=con.prepareStatement("select * from "+pname+" ");
ResultSet rs1=pst1.executeQuery();
while(rs1.next())
{
%>
<tr>
<td><input type="checkbox" /></td>
<td><%=rs1.getString(3) %></td>
<td><%=rs1.getString(2) %></td>
</tr>
<%
}
}
%>
</table>
<% }catch(Exception e)
{
e.printStackTrace();
}finally
{
}
%>
its not assigning the string to "pname"? can anyone plz help me.

hi friend,
you are trying to assign a value to the String variable pname by getting the value of field, probably the field value which you want to get is of other data type in your table election. Check the data type or fetch the record using field name rather index instead of
<%pname=rs.getString(1);%>
use the following
<%pname=rs.getString("field_name");%>
Thanks.
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.