java jdbc使用PreparedStatement执行mysql存储过程,,如下一小段代码,演示jd
分享于 点击 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(); } } }
用户点评