zoukankan      html  css  js  c++  java
  • 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();
        }
  • 相关阅读:
    line-block,white-space,overflow
    JS操作cookie
    C#的位运算
    小常识:变量的修饰符和DEMO
    JS等号的小注释
    关于谷歌浏览器的小常识
    P2568 GCD
    P2522 [HAOI2011]Problem b
    P3455 [POI2007]ZAP-Queries
    P1447 [NOI2010]能量采集
  • 原文地址:https://www.cnblogs.com/baisha/p/15463877.html
Copyright © 2011-2022 走看看