Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class prog2_11
  4. {
  5.  
  6. public static void main(String[] args)
  7. {
  8. // TODO Auto-generated method stub
  9. Connection connect;
  10. try
  11. {
  12. String driverName = "com.mysql.jdbc.Driver";
  13. Class.forName(driverName);
  14. String serverName = "localhost";
  15. String mybase = "base00";
  16. String url_="jdbc:mysql://" + serverName + "/" + mybase;
  17. String userName = "root";
  18. String password = "";
  19.  
  20. connect = DriverManager.getConnection(url_, userName, password);
  21.  
  22. String query = "SELECT * FROM tab00";
  23.  
  24. Statement stmt = connect.createStatement();
  25. ResultSet rs = stmt.executeQuery(query);
  26.  
  27. String temp;
  28. while(rs.next())
  29. {
  30. temp = rs.getString("name");
  31. System.out.println(temp);
  32. }
  33. connect.close();
  34.  
  35. }
  36. catch (Exception e)
  37. {
  38. // TODO: handle exception
  39.  
  40. }
  41.  
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement