This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet needs boolean??????

 
kriti sharma
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • 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);
}
}
}
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It helps to check the Javadoc.
 
Raj Chila
Ranch Hand
Posts: 128
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
thank you so much everybody here on the board.i am learning a lot!!!
 
Java Programmer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic