Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package javaapplication13;
  7.  
  8. /**
  9. *
  10. * @author CSE
  11. */
  12. import java.sql.*;
  13.  
  14. public class NewClass {
  15.  
  16. public static void main ( String [] args )
  17.  
  18. {
  19. Connection con=null;
  20. Statement statement;
  21. ResultSet result;
  22.  
  23. try
  24. {
  25. Class.forName("oracle.jdbc.driver.OracleDriver");
  26. con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","ABDOULAYE","R154310");
  27. statement=con.createStatement();
  28. //int a = 8;
  29.  
  30. result = statement.executeQuery("select * from T");
  31. while(result.next())
  32. {
  33. int num= result.getInt(1);
  34. String name= result.getString(2);
  35. System.out.println(num + " " + name);
  36. }
  37. statement.executeUpdate("update T set name = 'nein' where id=8");
  38. System.out.println("Successfully updated");
  39. statement.executeUpdate("delete from T where id=8");
  40. System.out.println("Successfully deleted");
  41. statement.executeUpdate("insert into T values(11,'aj')");
  42. System.out.println("Successfully inserted");
  43. while(result.next())
  44. {
  45. int num= result.getInt(1);
  46. String name= result.getString(2);
  47. System.out.println(num + " " + name);
  48. }
  49. }
  50.  
  51. catch (Exception e)
  52. {
  53.  
  54. System.out.println(e);
  55.  
  56. }
  57. }
  58.  
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement