Advertisement
Guest User

Untitled

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