Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1.  
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7.  
  8. public class JdbcExample2 {
  9.  
  10. public static void main(String args[]) {
  11. Connection con = null;
  12.  
  13. try {
  14. Class.forName("com.mysql.jdbc.Driver").newInstance();
  15. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jedi",
  16. "root", "qwerty");
  17.  
  18. if(!con.isClosed())
  19. System.out.println("Successfully connected to " +
  20. "MySQL server using TCP/IP...");
  21.  
  22. } catch(Exception e) {
  23. System.err.println("Exception: " + e.getMessage());
  24. } finally {
  25. try {
  26. if(con != null)
  27. con.close();
  28. } catch(SQLException e) {}
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement