java jdbc使用PreparedStatement执行mysql存储过程的代码

研发过程当中,把内容过程经常使用的内容段备份一次,下边内容段是关于java 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();
            }
        }
    }  复制代码
                                                                                                                                          
相关文章
相关标签/搜索