• 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

ResultSet needs boolean??????

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i compile this code it gives the following error:
abc.java:52: incompatible types
found : boolean
required: java.sql.ResultSet
ResultSet rsB=stB.execute(sqlB);
^
1 error

STRANGE!!!help me please!!!
import java.io.*;
import java.net.*;
import java.sql.*;
class A
{
public static void main(String str[])
{
new B("POST");
}
}

class B extends Thread
{
String job;
Connection con;
B(String job)
{
this.job=job;
this.start();
}
public void run()
{
if(job.equals("POST"))
{
try
{
new C();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc dbc:ForestDev","forestdev","forestdev");
Socket sB=new Socket("localhost",9090);
PrintWriter outB=new PrintWriter(sB.getOutputStream(),true);
BufferedReader brB=new BufferedReader(new InputStreamReader(sB.getInputStream()));
Statement stB=con.createStatement();
String sqlB="select * from transfer";
ResultSet rsB=stB.execute(sqlB);
while(rsB.next())
{
String sqlTemp=rsB.getString(2);
outB.println(sqlTemp);
String status=brB.readLine();
System.out.println(status);
}
rsB.close();
stB.close();
sB.close();
con.close();
outB.close();
brB.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
}

class C
{
Connection con;
C()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc dbc:ForestDev","forestdev","forestdev");
ServerSocket ssC=new ServerSocket(9090);
Socket sC=null;
sC=ssC.accept();
PrintWriter outC=new PrintWriter(sC.getOutputStream(),true);
BufferedReader brC=new BufferedReader(new InputStreamReader(sC.getInputStream()));
while(true)
{
String sqlC=brC.readLine();
Statement stC=con.createStatement();
stC.execute(sqlC);
outC.println("done");
stC.close();
}
/* con.close();
sC.close();
ssC.close();
outC.close();
brC.close();*/
}
catch(Exception e)
{
System.out.println(e);
}
}
}
 
Sheriff
Posts: 67747
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
It helps to check the Javadoc.
 
Ranch Hand
Posts: 128
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kriti,
It certainly pays to go through the Javadoc, the execute method returns a boolean and the executeQuery() returns a ResultSet.
execute should be followed by getResultSet() to get the ResultSet.
 
kriti sharma
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you so much everybody here on the board.i am learning a lot!!!
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see execute(sql) returns boolean type and u r catching it in ResultSet object.
To get ResultSet object use either executeQuery(sql) or getResultSet(sql) on Statement object.
 
Bear Bibeault
Sheriff
Posts: 67747
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
"Java Programmer",
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic