美文网首页
jsp连接SQL数据库

jsp连接SQL数据库

作者: Sommouns | 来源:发表于2019-04-29 14:32 被阅读0次
        String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        try{
            Class.forName(driver);
        }
        catch(Exception e){
            out.write("ERR1:"+e.getMessage());
            return;
        }
        String url = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=BBS";
        String user="sa";
        String pwd="123456";
        Connection conn = null;
        try{
            conn = DriverManager.getConnection(url, user, pwd);
            String sql = "insert into BBS_User values(?,?,?,?,?,?)";
            PreparedStatement pStatement = conn.prepareStatement(sql);
            pStatement.setString(1, "00001");
            pStatement.setString(2, "123");
            pStatement.setString(3, "tim");
            pStatement.setString(4, "3196");
            pStatement.setString(5, "male");
            pStatement.setString(6, "1");
            int n = pStatement.executeUpdate();
        }
        catch(SQLException e){
            out.write("ERR2:"+e.getMessage());
            return;
        }
        out.write("okk");
    

    相关文章

      网友评论

          本文标题:jsp连接SQL数据库

          本文链接:https://www.haomeiwen.com/subject/lfuynqtx.html