Guest User

Untitled

a guest
Nov 11th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.Statement;
  4.  
  5. public class DbConn {
  6. static Connection connection = null;
  7. static Statement statement = null;
  8.  
  9. public static Statement connect() throws Exception {
  10. String url = "jdbc:mysql://localhost:3306/";
  11. String dbName = "student";
  12. String driver = "com.mysql.jdbc.Driver";
  13. String userName = "root";
  14. String password = "";
  15. try {
  16. Class.forName(driver).newInstance();
  17. connection = DriverManager.getConnection(url + dbName, userName, password);
  18. statement = connection.createStatement();
  19. } catch (Exception e) {
  20. System.out.println("Ex : "+e.toString());
  21. }
  22. return statement;
  23. }
  24. }
Add Comment
Please, Sign In to add comment