Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5.  
  6. import com.mysql.jdbc.Statement;
  7.  
  8. class Main{
  9. public static void main(String []args)
  10. throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException{
  11. String url = "jdbc:mysql://localhost:3306/test";
  12. Statement sql;
  13. ResultSet rs;
  14. Class.forName("com.mysql.jdbc.Driver").newInstance ();
  15. Connection con = DriverManager.
  16. getConnection(url, "root", "root");
  17. sql = (Statement) con.createStatement();
  18. rs = sql.executeQuery("select * from persoane");
  19. while(rs.next())
  20. System.out.println("id="+rs.getInt("Id")+", nume= "+ rs.getString("nume")+ ", varsta="+rs.getInt(3));
  21.  
  22. MyFrame3 frm=new MyFrame3(sql);
  23. frm.setVisible(true);
  24. con.close();
  25. rs.close();
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement