PDA

Click to See Complete Forum and Search --> : [RESOLVED] How to Write SQL statements in Java Programs


KGComputers
Apr 21st, 2006, 10:38 AM
Hi,

How do I write SQL statements in Java code (ResultSet/Statement)...What are the delimiters for SQL statements...In VB the delimiters for SQL statements are:

1) ' string
2)# dates

and so on....

Hoping for any examples...Tutorials are also welcomed...Thanks

Greg :) :) :)

vbNeo
Apr 21st, 2006, 05:06 PM
I'm not sure I understand your question(I'm not an SQL geek though ;))

But AFAIK, SQL is to be written as a string and then passed to a method, in which case you wouldn't need a specific type for the variables themselves, it'd all be a matter of following the SQL syntax.

Correct me if I'm wrong? =).

ComputerJy
Apr 21st, 2006, 05:40 PM
I agree
and for the second part, SQL statement delimiters are the same for both languages

GaryMazzone
Apr 21st, 2006, 05:46 PM
The pound sign (#) is only used in MSAccess as a date deliminater. The rest of them ususally just use a single qoute around a valid date format

KGComputers
Apr 26th, 2006, 11:49 AM
Hi guys,,,

Thanks for the tips...Yup, I was referring to the sql statement being copied to a string variable..I used the single quotation in this sql statement and it did work...

Here is the sample code:

String sql = "INSERT INTO DeptSelection (DeptDescription,DeptID, DeptAddress1,DeptAddress2,DeptCity,DeptPostalCode) " +
"VALUES('"+getDeptDescription()+ "', "+getDeptTypeId()+", '"+ getDeptAddress1()+ "',
'" +getDeptAddress2()+ "','"+getDeptCity()+"','"+getDeptPostalCode()+"')";

How come java uses the symbol + in the getMethods.I just code the idea from a book?

Greg

:) :) :)

ComputerJy
Apr 26th, 2006, 01:11 PM
+ sign is used for String concatenation