Guest User

Untitled

a guest
Feb 9th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. package com.jdbc.test;
  2.  
  3. import sun.tools.java.ClassNotFound;
  4.  
  5. import java.sql.*;
  6.  
  7. public class test {
  8. public static void main (String[] args) {
  9. String URL="jdbc:mysql://localhost:3306/new_schema";
  10. String USERNAME="d";
  11. String PASSWORD="Q1w2e3r4t5y6&";
  12. try {
  13. Class.forName("com.mysql.jdbc.Driver");
  14. Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
  15. Statement statement = connection.createStatement();
  16. ResultSet resultSet=statement.executeQuery("SELECT * FROM employee");
  17. while (resultSet.next()){
  18. System.out.println(resultSet.getString(2));
  19. }
  20. resultSet.close();
  21. statement.close();
  22. connection.close();
  23. } catch (SQLException e) {
  24. e.printStackTrace();
  25. } catch ( ClassNotFoundException e) {
  26. e.printStackTrace();
  27. }
  28. }
  29. }
Add Comment
Please, Sign In to add comment