Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What is the JDBC syntax for using a literal or variable in a standard Statement?

JDBC literal standard syntax
0
Posted

What is the JDBC syntax for using a literal or variable in a standard Statement?

0

Location: http://www.jguru.com/faq/view.jsp?EID=593348 Created: Dec 21, 2001 Author: Joe Sam Shirah (http://www.jguru.com/guru/viewbio.jsp?EID=42100) First, it should be pointed out that PreparedStatement handles many issues for the developer and normally should be preferred over a standard Statement. Otherwise, the JDBC syntax is really the same as SQL syntax. One problem that often affects newbies ( and others ) is that SQL, like many languages, requires quotes around character ( read “String” for Java ) values to distinguish from numerics. So the clause: “WHERE myCol = ” + myVal is perfectly valid and works for numerics, but will fail when myVal is a String. Instead use: “WHERE myCol = ‘” + myVal + “‘” if myVal equals “stringValue”, the clause works out to: WHERE myCol = ‘stringValue’ You can still encounter problems when quotes are embedded in the value, which, again, a PreparedStatement will handle for you. Also see: What is the JDBC syntax for using a date literal or variable in

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123