0

I was Writing a code to connect data base and add the following code to my action.java

Connection connection=getConnection("UserBook","UserBook123","catalog","localhost"); 
    String sql="select BookName from book"; 
    PreparedStatement ps=null; 
    ps=connection.PreparedStatement(sql);
    ResultSet set=ps.executeQuery(); 
    while(set!=null&&set.next()) { 
    System.out.println(set.getString("BookName")); } 
    connection.close(); 

the error i get is "The method PreparedStatement(String) is undefined for the type Connection"
Need to know how i can resolve this problem

Edited by Reverend Jim: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by VernonDozier
0

I was Writing a code to connect data base and add the following code to my action.java

Connection connection=getConnection("UserBook","UserBook123","catalog","localhost"); 
        String sql="select BookName from book"; 
        PreparedStatement ps=null; 
        ps=connection.PreparedStatement(sql);
        ResultSet set=ps.executeQuery(); 
        while(set!=null&&set.next()) { 
        System.out.println(set.getString("BookName")); } 
        connection.close(); 

the error i get is "The method PreparedStatement(String) is undefined for the type Connection"
Need to know how i can resolve this problem

Spelling counts, and so does capitalization. I assume you want the prepareStatement function from Connection, which RETURNS a PreparedStatement. There are several, one of which takes a String.

http://www.j2ee.me/javase/6/docs/api/java/sql/Connection.html

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.