• JDBC_PreparedStatement


    插入数据

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException, NoSuchMethodException, InvocationTargetException, IOException {
            //加载配置文件
            InputStream is = Jdbc_test.class.getClassLoader().getResourceAsStream("jdbc.propertise");
            Properties properties = new Properties();
            properties.load(is);
            String user = properties.getProperty("user");
            String password = properties.getProperty("password");
            String url = properties.getProperty("url");
            String driver = properties.getProperty("driver");
            //连接数据库
            Class.forName(driver);
            Connection conn = DriverManager.getConnection(url,user,password);
            //插入语句
            String sql = "insert into emp values(default,?,?)"; //预编译语句
            PreparedStatement ps =conn.prepareStatement(sql);
            ps.setString(1,"admin1"); //设置参数
            ps.setString(2,"1234");     //设置参数
            ps.executeUpdate(); //执行
            //关闭资源
            ps.close();
            conn.close();
        }
  • 相关阅读:
    springMvc
    计算机网络
    Mybatis 总结
    Spring 面试总结
    Java IO 流
    自定义类加载器
    缓存一致性协议
    dfs、bfs序
    7.26
    Trick
  • 原文地址:https://www.cnblogs.com/baisha/p/15463877.html
Copyright © 2020-2023  润新知