主方法操作数据库【简单版】
public class JDBCDemo {
private static final String DATABASE_DRIVER = "com.mysql.jdbc.Driver" ;
private static final String DATABASE_URL = "jdbc:mysql://192.168.56.10:3306/gulimall_pms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai" ;
private static final String DATABASE_USER = "root" ;
private static final String DATABASE_PASSWORD = "root" ;
public static void main(String[] args) throws Exception{
Class.forName(DATABASE_DRIVER);
Connection connection = DriverManager.getConnection(DATABASE_URL,DATABASE_USER,DATABASE_PASSWORD);
String sql = "INSERT INTO user(id,name,age,email) VALUES (?,?,?,?)";
PreparedStatement pstmt = connection.prepareStatement(sql);
pstmt.setInt(1,1);
pstmt.setString(2,"张三");
pstmt.setInt(3,18);
pstmt.setString(4, UUID.randomUUID()+"@qq.com");
System.out.println(pstmt.execute());
}
}
|