my dog learned polymorphism*
The moose likes JDBC and the fly likes ResultSet TYPE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet TYPE" Watch "ResultSet TYPE" New topic
Author

ResultSet TYPE

Arun Maalik
Ranch Hand

Joined: Oct 25, 2005
Posts: 216
import java.sql.*;

public class first{
public static void main(String[] args){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.out.println(e);
}
try{
String str="select * from authors where au_id=?";
Connection con=DriverManager.getConnection("jdbcdbc:MyDataSource","sa","");
PreparedStatement pstmt=con.prepareStatement(str);

pstmt.setString(1,"672-71-3249");

ResultSet rs=pstmt.executeQuery();
System.out.println(rs.next());

String st=rs.getString("au_fname");
System.out.println(rs.isBeforeFirst());
System.out.println("Author first name is "+ st);

}
catch(SQLException e){
System.out.println(e);


}


catch(Exception e){
System.out.println(e);
}
}
}


Dear sir by the above code Result set will be type forward only. As we know that in static sql statment we add a method like con.createStatment(int,int,int); by this statement we change the state of result set like ResultSet.TYPE_SCROLL_SENSITIVE etc but with the preParedStatemnt what i have to add so that we can change the state of ResultSet in the above code it's throwing a Exception that ResultSet is type forward only.by following code
System.out.println(rs.isBeforeFirst());

withRegard

Arun
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

Arun,
con.prepareStatement() has a signature that takes three parameters:
1) SQL
2) ResultSetType
3) ResultSetConcurrency

What are you trying to accomplish with the printlns? There might be a cleaner way.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Arun Maalik
Ranch Hand

Joined: Oct 25, 2005
Posts: 216
Thanks sir
I have understood.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet TYPE
 
Similar Threads
java.io.NotSerializableException and java.io.WriteAbortedException
why Invalide cursor state exception
Problem while inserting data into MS SQL table
The "Next" is not working
Insert and MoveFirst