7 Replies - 9515 Views - Last Post: 21 October 2011 - 09:33 PM Rate Topic: -----

#1 idunno  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 10-October 11

Java inside Oracle ResultSet

Posted 11 October 2011 - 06:30 PM

Hi im am a newbie making a java method inside the oracle database
this code works..
#sql { INSERT INTO TABLE1 (COLUMN1) VALUES ("VALUE1") };


the problem is . . i want to query and put it in a java resultset
i tried this and failed
ResultSet rs = #sql { SELECT COLUMN1 FROM TABLE1};



how can i assign the query result inside the variable. .
thanks alot

Is This A Good Question/Topic? 0
  • +

Replies To: Java inside Oracle ResultSet

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10816
  • View blog
  • Posts: 40,318
  • Joined: 27-December 08

Re: Java inside Oracle ResultSet

Posted 11 October 2011 - 07:09 PM

The Java is separate from the Oracle database end. You have to use a Statement object in your Java program and executeQuery() in order to get a RestultSet back. Remember- this is not legal on the Oracle database end, only in your Java program.
Was This Post Helpful? 1
  • +
  • -

#3 idunno  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 10-October 11

Re: Java inside Oracle ResultSet

Posted 11 October 2011 - 07:25 PM

ahh ok
i tried the executeQuery()
but i dont know how to initialize the
connection(what should i put there, how will i know?)
conn = ?
stmt = conn.createStatement();
rs = stmt.executeQuery(query);



sorry i am new here..
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10816
  • View blog
  • Posts: 40,318
  • Joined: 27-December 08

Re: Java inside Oracle ResultSet

Posted 11 October 2011 - 07:39 PM

Moved to Java.

You have to get the Connection from the DriverManager.getConnection() method.

Check out these JDBC Tutorials:
http://www.dreaminco..._1&#entry250686
http://www.dreaminco...bc-odbc-bridge/
http://www.dreaminco...1&#entry1217697
Was This Post Helpful? 1
  • +
  • -

#5 mkoop  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 17
  • Joined: 14-April 11

Re: Java inside Oracle ResultSet

Posted 21 October 2011 - 10:42 AM

Read up on JDBC

String url = "jdbc:mysql://localhost/"; 
//your path -- its easier to make a method getConnection() that executes your connection and call that method.

Connection conn = DriverManager.getConnection(url, "username", "password");
Statement stmt = conn.createStatement(); 

String query = "SELECT description, count(*)
FROM engage e, financial_class fc
WHERE tek IN (SELECT het
              FROM vp
	      WHERE vp_code ='202.8' 
	      INTERSECT
	      SELECT het
	      FROM vp
	      WHERE vp_code = '399.0') 
AND e.class_code = fc.class_code
GROUP BY description
HAVING count(*) >= 10;"; //your query 

ResultSet rs = st.executeQuery(query);



The ResultSet object, rs, now contains the results of the query: the "first_name" and "last_name" columns for every record in the "people" table.
Was This Post Helpful? 2
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8347
  • View blog
  • Posts: 31,913
  • Joined: 06-March 08

Re: Java inside Oracle ResultSet

Posted 21 October 2011 - 08:38 PM

This is a valid Java statement to define a String object:
String query = "SELECT description, count(*) " +
"FROM engage e, financial_class fc " +
"WHERE tek IN (SELECT het " +
"              FROM vp " +
"	      WHERE vp_code ='202.8' " + 
"	      INTERSECT " +
"	      SELECT het " +
"	      FROM vp " +
"	      WHERE vp_code = '399.0')  " + 
"AND e.class_code = fc.class_code " +
"GROUP BY description " +
"HAVING count(*) >= 10;"; //your query 



Happy coding
Was This Post Helpful? 1
  • +
  • -

#7 mkoop  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 17
  • Joined: 14-April 11

Re: Java inside Oracle ResultSet

Posted 21 October 2011 - 09:30 PM

Thanks pbl -- my apologize op -- was in a rush getting out of the office this afternoon didn't proof my own stuff.
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8347
  • View blog
  • Posts: 31,913
  • Joined: 06-March 08

Re: Java inside Oracle ResultSet

Posted 21 October 2011 - 09:33 PM

No problem :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1