GAUTAM
asked on
Java Prepared Statement Problem
Hi Experts...
I have a prepared statement which queries StudentId,Names as shown below in code.
Here getNames function calls the runSutudentFetchQuery function by passing id one at a time.
I am getting the exception as below:
java.sql.SQLException: JZ0S3: The inherited method executeQuery(String) cannot be used in this subclass.
at com.sybase.jdbc2.jdbc.Erro rMessage.r aiseError( ErrorMessa ge.java:42 6)
at com.sybase.jdbc2.jdbc.SybP reparedSta tement.exe cuteQuery( SybPrepare dStatement .java:76)
at radioDb.runStudenttFetchQu ery(radioD b.java:88)
at radioDb.getNames(radioDb.j ava:25)
at Automate.main(radioAutomat .java:342)
whose description is
Description: PreparedStatement does not support executeQuery(String), executeUpdate(String), or execute(String).
Please help...
I have a prepared statement which queries StudentId,Names as shown below in code.
Here getNames function calls the runSutudentFetchQuery function by passing id one at a time.
I am getting the exception as below:
java.sql.SQLException: JZ0S3: The inherited method executeQuery(String) cannot be used in this subclass.
at com.sybase.jdbc2.jdbc.Erro
at com.sybase.jdbc2.jdbc.SybP
at radioDb.runStudenttFetchQu
at radioDb.getNames(radioDb.j
at Automate.main(radioAutomat
whose description is
Description: PreparedStatement does not support executeQuery(String), executeUpdate(String), or execute(String).
Please help...
public static ResultSet getNames(String ID)
{
String query="select StdentId,SName";
query+=" from dbo.Student";
query+=" where studentID=?";
ResultSet rs=runStudentFetchQuery(query,ID);
return rs;
}
public static ResultSet runStudentFetchQuery(String query,String ID)
{
Connection conn=null;
ResultSet result=null;
try
{
conn = getConnection();
PreparedStatement stat = conn.prepareStatement(query);
stat.setString(1,ID);
result = stat.executeQuery(query);
return result;
}
catch(IOException e)
{
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
conn.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
return result;
}
ASKER
@reijnemans:Yes i saw that.
How do i solve this.
Please help...
How do i solve this.
Please help...
use the method createStatement not prepareStaement.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
uncomment the line
// conn = getConnection();
ASKER
@reijnemans:i tried the below query.
I passed an id an it returns the error:com.sybase.jdbc2.jdb c.SybSQLEx ception: Invalid column name 'SS15'
But if i run the same query directly i get the correct values i.e:-StudentID,Studentname
Please help....
I passed an id an it returns the error:com.sybase.jdbc2.jdb
But if i run the same query directly i get the correct values i.e:-StudentID,Studentname
Please help....
public static ResultSet getNames(String ID) {
String query = "select StdentId,SName";
query += " from dbo.Student";
query += " where studentID = " + ID;
ResultSet rs = runStudentFetchQuery(query, ID);
return rs;
}
ASKER
@reijnemans:How do i single quote the value SS15.
If single quoted it will not cause the error.
Please help...
If single quoted it will not cause the error.
Please help...
ASKER
@reijnemans:Thanks a lot solved it.
query+=" where StudentID = '"+ID+ "'";
query+=" where StudentID = '"+ID+ "'";
The inherited method _____ cannot be used in this subclass.
Description: PreparedStatement does not support executeQuery(String), executeUpdate(String), or execute(String).
Action: If you want to pass a query string, use Statement, not PreparedStatement.