×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Massimo Zappino
Added: Jan 29, 2011 7:32 PM
Views: 129
  1. public class OracleJdbcTest
  2. {
  3.     String driverClass = "oracle.jdbc.driver.OracleDriver";
  4.  
  5.     Connection con;
  6.  
  7.     {
  8.         Properties props = new Properties();
  9.         props.load(fs);
  10.         String url = props.getProperty("db.url");
  11.         String userName = props.getProperty("db.user");
  12.         String password = props.getProperty("db.password");
  13.         Class.forName(driverClass);
  14.  
  15.         con=DriverManager.getConnection(url, userName, password);
  16.     }
  17.  
  18.     public void fetch() throws SQLException, IOException
  19.     {
  20.         PreparedStatement ps = con.prepareStatement("select SYSDATE from dual");
  21.         ResultSet rs = ps.executeQuery();
  22.  
  23.         while (rs.next())
  24.         {
  25.             // do the thing you do
  26.         }
  27.         rs.close();
  28.         ps.close();
  29.     }
  30.  
  31.     public static void main(String[] args)
  32.     {
  33.         OracleJdbcTest test = new OracleJdbcTest();
  34.         test.init();
  35.         test.fetch();
  36.     }
  37. }