Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help with the resultset problem

 
Boon Subra
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,
I am trying to find if a particular string is available in a String using 'instr' function..I dont get the output.The line rs= pstmt.executeQuery is not functioning.Please help me out

public int checkFiles(int acuserid,String fileid,String files)
{

ResultSet rs = null;
PreparedStatement pstmt = null;

int userid=0;
System.out.println("Hai");
try
{
String sql = "select instr(\'"+files+"\',\'"+fileid+"\',1) from clientinfonew where CL_ACUSERID=\'"+acuserid+"\'";
System.out.println(sql);
// I can execute this output in oracle
conn.prepareStatement(sql);
System.out.println("Hello");//okay
rs = pstmt.executeQuery();

//I cannot get the output from here
System.out.println("Hello1111111");
if(rs.next())
{
userid=rs.getInt(1);
System.out.println(userid);
}
rs.close();
pstmt.close();

}
catch(Exception e)
{
userid=0;
}

finally
{
return userid;
}
}
I put the following code in the main method along with the connection
String fileid ="1";
String files="5,2,1";
int stat = clinfo.checkFiles(4,fileid,files);
System.out.println(stat);

I am not able to proceed further .Please help me out.
Thanks to all,
Bhuvana
 
Jan Modaal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what exception does occeur exactly ?
or you could just try using the following:
 
darryl nortje
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your code "
String sql = "select instr(\'"+files+"\',\'"+fileid+"\',1) from clientinfonew where CL_ACUSERID=\'"+acuserid+"\'";
System.out.println(sql);
// I can execute this output in oracle
conn.prepareStatement(sql);
System.out.println("Hello");//okay
rs = pstmt.executeQuery();
"
Let me guess, you're getting a NullPointerException
try this
pstmt = conn.prepareStatement(sql);
I think that'll help
cheers
Darryl
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"darryl the second nortje",
We're pleased to have you here with us in the JDBC forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Thanks!
bear
Forum Bartender
 
Boon Subra
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daryl and Jan ,,
Thanks for the prompt response.
pstmt= conn.prepareStatement works. I am v.sorry .it was typo error.

Thanks a lot once again.
Bhuvana
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic