?
Solved

java program to query the database

Posted on 2012-08-29
7
Medium Priority
?
773 Views
Last Modified: 2012-08-29
I was trying following java program
http://www.exampledepot.com/egs/java.sql/CreateResultSet.html

Through java program Below one is working fine.                            
Statement stmt = connCdms.createStatement();
ResultSet rs1 = stmt.executeQuery("SELECT * FROM table1");

through java program Below one is not working
Statement stmt = connCdms.createStatement();
ResultSet rs1 = stmt.executeQuery("SELECT * FROM table1 col1='PPP' and col2='777'");

When i execute below query in toad on oracle database it returns 4 records. I am missing something. Please advise

SELECT * FROM table1 col1='PPP' and col2='777'

Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
  • 3
  • 3
7 Comments
 
LVL 7

Author Comment

by:gudii9
ID: 38346720
do i need to put / or something. please advise
0
 
LVL 32

Expert Comment

by:awking00
ID: 38346721
You're missing the WHERE keyword.
0
 
LVL 7

Author Comment

by:gudii9
ID: 38346763
I am sorry that is typo

I do have where clause as below still does not yield any results from the java program. (works perfect from toad)

SELECT * FROM table1 where col1='PPP' and col2='777'
Please advise
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 74

Assisted Solution

by:sdstuber
sdstuber earned 200 total points
ID: 38346845
did you insert the rows in toad? then not commit?

if so, no other session (java, sql *plus, another instance of toad, etc) will be able to see the data
0
 
LVL 7

Author Comment

by:gudii9
ID: 38346908
i did commit all is committed data existing for long time. Please advise
0
 
LVL 32

Accepted Solution

by:
awking00 earned 1800 total points
ID: 38346925
That looks okay to me but, since you said there was already a typo, is it possible that the actual code is showing ' '' (3 single quotes) as opposed to ' " (1 single, 1 double)?
Have you tried something like -
String query = "SELECT * FROM table1 where col1='PPP' and col2='777' ";
ResultSet rs1 = stmt.executeQuery(query);
0
 
LVL 32

Expert Comment

by:awking00
ID: 38346986
You might also try -
String query = "SELECT * FROM table1 where col1='PPP' and col2='777' ";
PreparedStatement pst = connCdms.prepareStatement(query);
ResultSet rs1 = pst.executeQuery();
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question