Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. public static void main(String args[]){
  2. try{
  3. //step1 load the driver class
  4. Class.forName("oracle.jdbc.driver.OracleDriver");
  5.  
  6. //step2 create the connection object
  7. Connection con=DriverManager.getConnection(
  8. url,username,password);
  9.  
  10. System.out.println("Connection Done");
  11.  
  12. //step3 create the statement object
  13. Statement stmt=con.createStatement();
  14.  
  15.  
  16. Date date = new Date ();
  17. long time = date.getTime();
  18. Timestamp ts = new Timestamp(time);
  19. //STEP 4: Execute a query
  20. System.out.println("Inserting records into the table...");
  21. int temp=123;
  22.  
  23. String sql="INSERT INTO TEST (INSERTED_DATE,CTID)" +"Values ("+ts+","+temp+");";
  24.  
  25. PreparedStatement statement
  26. = con.prepareStatement(sql);
  27.  
  28. System.out.println("Inserted records into the table...");
  29. statement.executeUpdate();
  30.  
  31.  
  32. //step5 close the connection object
  33. con.close();
  34. System.out.println("Goodbye!");
  35. }catch(Exception e){
  36. e.printStackTrace();
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement