Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

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
Avatar of gudii9
gudii9
Flag of United States of America image

ASKER

do i need to put / or something. please advise
Avatar of awking00
You're missing the WHERE keyword.
Avatar of gudii9

ASKER

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
SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

i did commit all is committed data existing for long time. Please advise
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You might also try -
String query = "SELECT * FROM table1 where col1='PPP' and col2='777' ";
PreparedStatement pst = connCdms.prepareStatement(query);
ResultSet rs1 = pst.executeQuery();