Advertisement
Guest User

Untitled

a guest
Apr 7th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. /**
  2. java 链接jdbcdemo
  3. ***/
  4. public Connection getConn() {
  5. String driver = "com.mysql.jdbc.Driver";
  6. String url = "jdbc:mysql://localhost:3306/samp_db";
  7. String username = "root";
  8. String password = "";
  9. Connection conn = null;
  10. try {
  11. Class.forName(driver); //classLoader,加载对应驱动
  12. conn = (Connection) DriverManager.getConnection(url, username, password);
  13. } catch (ClassNotFoundException e) {
  14. e.printStackTrace();
  15. } catch (SQLException e) {
  16. e.printStackTrace();
  17. }
  18. return conn;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement