Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet TYPE

 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks sir
I have understood.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic