How do I bind string values in a PreparedStatement?
Submitted by: AdministratorSuppose you are trying to tget the PreparedStatement class to bind Strings in a statement. The setString() method doesn't seem to work. Here is how you have set up the PreparedStatement:
String pstmt = "select n_name from n_table where n_name LIKE
'?%'";
PreparedStatement ps = conn.prepareStatement(pstmt);
ps.setString(1, "SMIT");
ResultSet rs = ps.executeQuery();
The preceding code does not work because the complete value needs to be specified in a String (without using embedded quotes) and then bound to an unquoted question-mark (?). Here is the corrected code:
String matchvalue = "smit%";
String pstmt = "select n_name from n_table where n_name LIKE ?";
PreparedStatement ps = conn.prepareStatement(pstmt);
ps.setString(1, matchvalue);
ResultSet rs = ps.executeQuery();
Submitted by: Administrator
String pstmt = "select n_name from n_table where n_name LIKE
'?%'";
PreparedStatement ps = conn.prepareStatement(pstmt);
ps.setString(1, "SMIT");
ResultSet rs = ps.executeQuery();
The preceding code does not work because the complete value needs to be specified in a String (without using embedded quotes) and then bound to an unquoted question-mark (?). Here is the corrected code:
String matchvalue = "smit%";
String pstmt = "select n_name from n_table where n_name LIKE ?";
PreparedStatement ps = conn.prepareStatement(pstmt);
ps.setString(1, matchvalue);
ResultSet rs = ps.executeQuery();
Submitted by: Administrator
Read Online BEA Weblogic Job Interview Questions And Answers
Top BEA Weblogic Questions
☺ | Can I use the getAttribute() and setAttribute() methods of Version 2.2 of the Java Servlet API to parse XML documents? |
☺ | Which of the following are the benefits of MDB (Message Driven Beans) over standard JMS consumers? |
☺ | Why do I get an error while trying to retrieve the text for ORA-12705? |
☺ | Why am I getting an ORA-01000: maximum open cursors exceeded error, even though I closed all ResultSet, Statement, and Connection objects? |
☺ | Can WebLogic Server start with a UNIX boot? |
Top Application Program Categories
☺ | AutoCAD Interview Questions. |
☺ | Microsoft Office Interview Questions. |
☺ | Microsoft Outlook Interview Questions. |
☺ | Microsoft Excel Interview Questions. |
☺ | WPF Interview Questions. |