Advertisement
Guest User

Untitled

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