Guest User

Untitled

a guest
Feb 19th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. /*import javax.servlet.*;
  2. import javax.servlet.http.*; */
  3. import java.sql.*;
  4. import java.sql.Connection.*;
  5.  
  6. public class ralph {
  7. public static void main(String[] args)
  8. {
  9. javax.swing.JOptionPane.showMessageDialog(null,"this is a test!!");
  10. Connect();
  11. }
  12.  
  13.  
  14.  
  15. static void Connect()
  16. {
  17. Connection con = null;
  18. Statement stm;
  19. try
  20. {
  21. Class.forName("com.mysql.jdbc.Driver");
  22. }
  23. catch(java.lang.ClassNotFoundException e)
  24. {
  25. System.err.print("ClassNotFoundException: ");
  26. System.err.println(e.getMessage());
  27. javax.swing.JOptionPane.showMessageDialog(null, e.getMessage());
  28. }
  29.  
  30. try
  31. {
  32. con=DriverManager.getConnection("Jdbc:mysql://localhost:3306/ralph?"+"user=root&password=roots");
  33. stm=con.createStatement();
  34. String strQry="select * from user_acc";
  35. ResultSet rs = stm.executeQuery(strQry);
  36.  
  37. while (rs.next())
  38. {
  39. System.out.println(rs.getString(1) + rs.getString(2) + rs.getString(3));
  40. }
  41.  
  42. con.close();
  43. }
  44. catch(Exception e)
  45. {
  46. System.out.println(e);
  47. javax.swing.JOptionPane.showMessageDialog(null, e.getMessage());
  48. }
  49. }
  50.  
  51. }
Add Comment
Please, Sign In to add comment