Advjava 3
Advjava 3
To Send a request the database and retrieve results from the database we need to create statements.
CallableStatement
Confidential
Statement
This is an interface provided by JDBC- API to process the simple JDBC queries to the Database.
setMaxRows()
getMaxRows(); close()
Confidential
} }
while(rs.next())
{ System.out.println("User Name "+rs.getString(1)); System.out.println("Pin Number "+rs.getString(2));
catch(Exception e)
} }
{
System.out.println(e); }
Confidential
PreparedStatement
This interface is provide by the JDBC-API to process parameterized Query to the database.
setString()
setInt() setDouble() close();
Confidential
ResultSet rs=stat.executeQuery();
while(rs.next()) { System.out.println("User Name "+rs.getString(1)); System.out.println("Pin Number "+rs.getString(2)); } catch(Exception e) {
} } }
System.out.println(e);
Confidential
CallableSatement
This is an interface provided by JDBC- API to process Stored Procedure calls.
setDouble()
getString() getInt() getDouble() close()
Confidential
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:dsn1","sa",""); String str="{call MyProcedure(?,?,?,?)}"; CallableStatement cs=con.prepareCall(str); cs.setString(1,"1001"); cs.registerOutParameter(2,Types.VARCHAR); cs.registerOutParameter(3,Types.VARCHAR); cs.registerOutParameter(4,Types.VARCHAR); cs.execute(); String fname=cs.getString(2); String lname=cs.getString(3); String city=cs.getString(4); System.out.println(fname); } catch(Exception e) {
} } }
System.out.println(e);
Confidential