String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/test";
String username = "root";
String password = "123456";
Class.forName(driver);//加载驱动
Connection con = DriverManager.getConnection(url, username, password);//获得数据库连接
//预编译sql语句的编写
//增加数据
String sql = "insert into user (name,gender,age,address) values (?,?,?,?)";
//删除数据
String sql = "delete from user where id=?";
//修改数据
String sql = "update user set name=?, gender=?, age=? ,address=? where id=?";
//查询数据
String sql = "select *from user";