Advertisement
Guest User

Untitled

a guest
May 24th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. class test1
  4. {
  5. public static void main(String [] args)
  6. {
  7. try
  8. {
  9. Class.forName("oracle.jdbc.OracleDriver");
  10.  
  11. System.out.println("Driver loaded successfully");
  12. }
  13. catch(ClassNotFoundException ex)
  14. {
  15. System.out.println("Could not load "+ex.getMessage());
  16. System.exit(0);
  17. }
  18. Connection con=null;
  19. try
  20. {
  21. con=DriverManager.getConnection("jdbc:oracle:thin:@//Apoorv-PC:1521/orcl","scott","tiger");
  22. Statement st=con.createStatement();
  23. //st.setMaxRows(2);
  24. //System.out.println(st.getMaxRows());
  25. ResultSet rs=st.executeQuery("Select park_space from park_available where area='M.P.Nagar'");
  26.  
  27. while(rs.next())
  28. {
  29. String p=rs.getString(1);
  30. System.out.println(" "+p);
  31. }
  32. con.close();
  33. System.out.println("Connection closed!");
  34. }
  35. catch(SQLException e)
  36. {
  37. System.out.println("Error in database"+e.getMessage());
  38. }
  39. if(con!=null)
  40. {
  41. System.out.println("Successful!");
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement