aspose file tools*
The moose likes JDBC and the fly likes help in sql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "help in sql " Watch "help in sql " New topic
Author

help in sql

Mary Wallace
Ranch Hand

Joined: Aug 25, 2003
Posts: 138
I have a sql statement like this

pin and account number is not passing the values. system .out print is showing this select pin,emp_acct_no,attn_name,address_line1,address_line2,po_box_no,city,state,zip,country_code,emailFROM w_employer WHERE pin= 'pinum' and emp_acct_no=checkaccountNumber
DB Connection Error(validate accountnumer): java.sql.SQLException: ORA-00923: FROM keyword not found where expected
what Im doing wrong here?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9


String qry = "select pin,emp_acct_no,attn_name,address_line1,address_line2,po_box_no,city,state,zip,country_code,email" +
"FROM w_employer WHERE pin='" + pinnum + " 'AND emp_acct_no="+checkaccountNumber;

There's no space between "country_code,email" and "FROM". They get concatenated and the SQL compiler can't find the FROM keyword.


[How To Ask Questions On JavaRanch]
Mary Wallace
Ranch Hand

Joined: Aug 25, 2003
Posts: 138
I changed like this and it worked

i want to change that as a prepared statement like this:

but it gave me an error "DB Connection Error(validate pin frm db): java.sql.SQLException: ORA-00923: FROM keyword not found where expected"
what i have to do here?
thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Did you read Joe's response?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mary Wallace
Ranch Hand

Joined: Aug 25, 2003
Posts: 138
The problem was not bcoz of the space as Joe suggested.When i rewrote the sql it worked.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

Your String query has a space before FROM but the String literal in your prepared statement doesn't have the space. Attention to detail!
Mary Wallace
Ranch Hand

Joined: Aug 25, 2003
Posts: 138
thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: help in sql