Guest User

Untitled

a guest
Mar 23rd, 2016
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import java.sql.*
  2. public class SimpleJdbc{
  3.  
  4. public static void main (String[] args) throws exception{
  5.  
  6. Class.forName("com.mysql.jdbc.Driver");
  7. System.out.println("Driver loaded");
  8.  
  9. Connection connection=DriverManager.getConnection("jdbc:mysql://localhost/db","root","root");
  10. System.out.println("Database connected");
  11. Statement statement = connection.createStatement();
  12.  
  13. ResultSet resultSet=statement.executeQuery("select * from Student");
  14. while(resultSet.next())
  15. System.out.println(resultSet.getString(1)+"\t" + resultSet.getInt(2));
  16. connection.close();
  17. }
  18. }
Add Comment
Please, Sign In to add comment