java - Issue with prepared statement when using select query with string -


i have written simple jdbc program query , trying create prepared statement, result set coming empty. when same query executed through general statement creation gives output , through sql plus.

package com.aexp.balu.jdbc;  import java.io.reader; import java.sql.*;  public class simpleconnection {      public static void main(string[] args) {         // todo auto-generated method stub          // string url="url";         // string uname="uname";         // string pass="password";         string url = "url";         string uname = "uname";         string pass = "password";         string query = "select card_no mdc.cas_unmch_rocs card_no = ?";         string cardnumber = "3222222222222222223";          try {              // step1 load driver class             system.out.println("registering driver");             class.forname("oracle.jdbc.driver.oracledriver");              // step2 create connection object . need have type of             // connection             // drivermanager class has method connection give             // sthe instance of connection              system.out.println("creating connection....");             connection con = drivermanager.getconnection(url, uname, pass);              // step3 create statement object             system.out.println("creating statement");              preparedstatement stmt = con.preparestatement(query);              stmt.setstring(1, cardnumber);              // step4 execute query -- stmnt object of method execute             // query results object             // of result set             system.out.println("executing query");              resultset rs = stmt.executequery();             system.out.println("after executing query");              while (rs.next()) {                 system.out.println(" in reading result set");                  string cardnumber = rs.getstring("card_no");                  system.out.println(cardnumber);              }             // step5 close connection object             rs.close();             stmt.close();             con.close();          } catch (exception e) {              e.printstacktrace();          }      } } 

the output this:

registering driver creating connection.... creating statement executing query after executing query 


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -