• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please help with the resultset problem

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what exception does occeur exactly ?
or you could just try using the following:
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic