首先你需要导入MySQL的jar包。
加载数据库驱动:
Class.forName("com.mysql.jdbc.Driver")
建立连接:
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db_book", "userName", "password");
进行相应的CRUD操作:
String sql = "select * from t_user";
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery()
关闭资源:
conn.close();
pstmt.close();
rs.close();