Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class ClientPersist {
  4.  
  5. public static void main(String[] args) {
  6. // TODO Auto-generated method stub
  7.  
  8. try {
  9.  
  10. Class.forName("com.mysql.jdbc.Driver");
  11.  
  12. Connection conn;
  13.  
  14. conn = DriverManager.getConnection(
  15. "jdbc:mysql://localhost/classicmodels?user=classicmodels&password=classicmodels");
  16.  
  17. Statement stmt;
  18. stmt = conn.createStatement();
  19.  
  20. ResultSet rs = stmt.executeQuery("select * from Produit");
  21.  
  22. while (rs.next()) {
  23. System.out.println(rs.getInt("empno") + ", " +
  24. rs.getString("ename") + ", " + rs.getInt("deptno"));
  25. }
  26.  
  27. stmt.close();
  28. conn.close();
  29.  
  30. } catch (SQLException e) {
  31.  
  32. System.out.println("A database error occurred:" + e.getMessage());
  33.  
  34. } catch (ClassNotFoundException e) {
  35.  
  36. System.out.println("Driver not found: " + e.getMessage());
  37.  
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement