Guest User

Untitled

a guest
Dec 30th, 2018
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. package databasetest1;
  2. import java.sql.*;
  3.  
  4. public class Connectiontest1 {
  5.  
  6. public static void main(String[] args) {
  7. // TODO Auto-generated method stub
  8. try{
  9. //step1 load the driver class
  10. Class.forName("oracle.jdbc.driver.OracleDriver");
  11.  
  12. //step2 create the connection object
  13. Connection con=DriverManager.getConnection( "jdbc:oracle:thin:@172.20.20.168:1521:ORCL","scott","tiger");
  14.  
  15. //step3 create the statement object
  16. Statement stmt=con.createStatement();
  17.  
  18. //step4 execute query
  19. PreparedStatement stmt1=con.prepareStatement("insert into EMPPPP values(?,?)");
  20. PreparedStatement stmt2=con.prepareStatement("Delete from EMPPPP where id=4");
  21.  
  22. stmt1.setInt(1,1);//1 specifies the first parameter in the query
  23. stmt1.setString(2,"hello");
  24.  
  25. int i=stmt1.executeUpdate();
  26. int i1=stmt2.executeUpdate();
  27. System.out.println(i+" records inserted");
  28.  
  29. ResultSet rs=stmt.executeQuery("select * from EMPPPP");
  30. while(rs.next())
  31. System.out.println(rs.getString(1)+" "+rs.getString(2));
  32.  
  33. //step5 close the connection object
  34. //con.close();
  35.  
  36. }catch(Exception e){ System.out.println(e);}
  37.  
  38.  
  39. }
  40.  
  41. }
Add Comment
Please, Sign In to add comment