[RESOLVED] How to Write SQL statements in Java Programs
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 :) :) :)
Re: How to Write SQL statements in Java Programs
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? =).
Re: How to Write SQL statements in Java Programs
I agree
and for the second part, SQL statement delimiters are the same for both languages
Re: How to Write SQL statements in Java Programs
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
Re: How to Write SQL statements in Java Programs
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:
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
:) :) :)
Re: How to Write SQL statements in Java Programs
+ sign is used for String concatenation