Guest User

Untitled

a guest
Apr 4th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 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 jdbcapp;
  7. import java.sql.*;
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10.  
  11. /**
  12. *
  13. * @author abhis
  14. */
  15. public class DatabaseProgram {
  16.  
  17. /**
  18. * @param args the command line arguments
  19. */
  20. public static void main(String[] args) {
  21. // TODO code application logic here
  22. try
  23. {
  24. Class.forName("oracle.jdbc.driver.OracleDriver");
  25. Connection con;
  26. con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","system");
  27. System.out.println("connected");
  28. Statement stmt=con.createStatement();
  29. stmt.execute("create table student211(Fname varchar(10),Contno number(10))");
  30. System.out.println("table created");
  31. stmt.executeUpdate("insert into student211 values('pk',12345)");
  32. System.out.println("Data inserted");
  33. stmt.executeUpdate("update student211 set Fname='sk' where contno=12345");
  34. System.out.println("Data updated");
  35. ResultSet rs=stmt.executeQuery("select * from student211");
  36. while(rs.next())
  37. {
  38. System.out.println(rs.getString(1));
  39. System.out.println(rs.getString(2));
  40. }
  41. }
  42.  
  43.  
  44.  
  45.  
  46. catch (ClassNotFoundException | SQLException ex) {
  47. Logger.getLogger(DatabaseProgram.class.getName()).log(Level.SEVERE, null, ex);
  48. }
  49. }}
Add Comment
Please, Sign In to add comment