• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 776
  • Last Modified:

java program to query the database

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
gudii9
Asked:
gudii9
  • 3
  • 3
2 Solutions
 
gudii9Author Commented:
do i need to put / or something. please advise
0
 
awking00Commented:
You're missing the WHERE keyword.
0
 
gudii9Author Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
sdstuberCommented:
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
 
gudii9Author Commented:
i did commit all is committed data existing for long time. Please advise
0
 
awking00Commented:
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
 
awking00Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now