Sample JDBC coding(2)

Post date: Mar 08, 2012 10:46:59 PM

public String getName(int id) throws Exception{

ResultSet resSet = null;

MyDBStatement is = new MyDBStatement(ic);

String name;

String qry;

try {

Qry = "select name from order";

Qry += " where id=" + id;

is.execute(Qry);

resSet = is.getResultSet();

if (resSet.next() ) {

name=resSet.getString("name");

}

} catch (Exception e) {

ic.debug(className+"getName throws exception " + e.toString());

} finally {

if (resSet != null) resSet.close();

if ( is != null ) is.close();

}

return name;

}

look for ResultSet API in http://docs.oracle.com/javase/1.5.0/docs/api/java/sql/ResultSet.html