PreparedStatement基本操作步骤

1.获取连接
   1)读取配置文件中的四个基本信息  
     

      a.将配置文件转换成字流         InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("jdbc.properties");
      b.将资源加载                           Properties pros = new Properties();   pros.load(is);
      c.分别接收四个基本信息
            String user = pros.getProperty("user");
            String password = pros.getProperty("password");
            String url = pros.getProperty("url");
            String driver = pros.getProperty("driver");
   2)加载驱动    Class.forName(driver);
   3)获取连接    Connection con = DriverManager.getConnection(url, user, password);
2.预编译
3.填充占位符
4.执行
5//...具体操作

「jdbc.properties」
user=root
password={*******}
url=jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC
#url=jdbc:mysql://127.0.0.1:3306/test?user=root&password={******}&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
driver=com.mysql.cj.jdbc.Driver
 

猜你喜欢

转载自blog.csdn.net/qq_44400944/article/details/117884792