ossiejhmoore

Untitled

Nov 14th, 2018
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. package com.kw.example.jdbc;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7.  
  8. public class Java_JDBCExample {
  9.  
  10.     public static void main(String[] args) {
  11.         String driver = "oracle.jdbc.driver.OracleDriver";
  12.         String url = "jdbc:oracle:thin:@localhost:1521:orcl";
  13.         String user = "rmnausr";
  14.         String pass = "opentext";
  15.  
  16.         try {
  17.             Class.forName(driver);
  18.             Connection con = DriverManager.getConnection(url, user, pass);
  19.             PreparedStatement stmt = con.prepareStatement("select * from dtree where parentid = ?");
  20.             stmt.setInt(1, 2000);
  21.             ResultSet rs = stmt.executeQuery();
  22.             while(rs.next()) {
  23.                 System.out.printf("DataId: %s, Name: %s%n", rs.getInt("DATAID"), rs.getString("NAME"));
  24.             }
  25.             rs.close();
  26.             stmt.close();
  27.             con.close();
  28.         } catch (Throwable t) {
  29.             System.err.printf("Crap! %s", t.getLocalizedMessage());
  30.             t.printStackTrace();
  31.         }
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment