2014-08-04 06:30:02
阅读( 491 )
如下一小段代码,演示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();
}
}
}
分享给朋友:
亲~ 如果您有更好的答案 可在评论区发表您独到的见解。
您想查看更多的信息:
面试题