欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java jdbc使用PreparedStatement执行mysql存储过程,,如下一小段代码,演示jd

来源: javaer 分享于  点击 47459 次 点评:270

java jdbc使用PreparedStatement执行mysql存储过程,,如下一小段代码,演示jd


如下一小段代码,演示jdbc使用PreparedStatement执行mysql存储过程:

      private static void doStatistics(PublicSentimentLite psl) throws SQLException,            InstantiationException, IllegalAccessException, ClassNotFoundException {        Connection con = null;        try {            Class.forName("com.mysql.jdbc.Driver").newInstance();            con = DriverManager.getConnection(ConfigLoader.getConnString(),                    ConfigLoader.getDatabaseUser(), ConfigLoader.getDatabasePassword());            String sql = "CALL proc_nstatistics_update_by_ps(?,?,?,?,?)";            PreparedStatement pstmt = con.prepareStatement(sql);            pstmt.setString(0, psl.getCategoryCode());            pstmt.setDate(1, new java.sql.Date(psl.getPublishTime().getTime()));            pstmt.setInt(2, psl.getAttribute());            pstmt.setString(3, psl.getMediaType());        } finally {            if (con != null) {                con.close();            }        }    }
相关栏目:

用户点评