How to write a program to bind string values in a PreparedStatement?
Submitted by: AdministratorThe PreparedStatement class allow to bind the string values in the class. The setString() method that can be used with it won't work due to incompatibility. The example shows the usage of the PreparedStatement:
String pstmt = "select n_name from n_table where n_name LIKE '?%'";
PreparedStatement ps = conn.prepareStatement(pstmt);
ps.setString(1, "Rohit");
ResultSet rs = ps.executeQuery();
This PreparedStatement doesn't work due to the fact that the value needs to be specified in a string and not be embedded in quotes. The corrected statement that gets executed is as follows:
String matchvalue = "rohit%";
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, "Rohit");
ResultSet rs = ps.executeQuery();
This PreparedStatement doesn't work due to the fact that the value needs to be specified in a string and not be embedded in quotes. The corrected statement that gets executed is as follows:
String matchvalue = "rohit%";
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 Web Logic Server Job Interview Questions And Answers
Top Web Logic Server Questions
☺ | Do you know what is the local interface used by web logic server? |
☺ | Explain where are the files placed while deploying the resource adapter in web logic server? |
☺ | Explain what is the purpose of stub in web-logic server cluster? |
☺ | Tell me how are the notifications generated when a server is added to a cluster? |
☺ | Explain what are the transaction isolation levels supported by WebLogic jDriver? |
Top Servers (Computing) Categories
☺ | Windows Server 2008 Interview Questions. |
☺ | Exchange Server 2007 Interview Questions. |
☺ | MS Exchange Server 2003 Interview Questions. |
☺ | Windows Server 2003 Interview Questions. |
☺ | ATL Server Interview Questions. |