バッチ更新を行うことは可能ですが、ステートメントが異なりますか?私が見つけたすべてのチュートリアルとオンラインリソースは同じステートメントを使用しています。これは私が持っているものですが、機能していません。
public static void resetNotifications(User user)
{
DataSource dataSource = null;
Context initialContext = null;
Context environmentContext = null;
Connection connection = null;
PreparedStatement preparedStatement = null;
String stride = "UPDATE stride SET recipientView = 1 WHERE recipientId = ?";
String strideLike = "UPDATE strideLike SET recipientView = 1 WHERE recipientId = ? ";
String strideCommentMe = "UPDATE strideComment SET recipientView = 1 WHERE recipientId = ? ";
String strideCommentLike = "UPDATE strideCommentLike SET recipientView = 1 WHERE recipientId = ? ";
String strideCommentFollow = "UPDATE strideCommentNotification SET recipientView = 1 WHERE userId = ? ";
try
{
initialContext = new InitialContext();
environmentContext = (Context) initialContext.lookup("java:/comp/env");
dataSource = (DataSource) environmentContext.lookup("jdbc/instride");
connection = dataSource.getConnection();
connection.setAutoCommit(false);
preparedStatement = connection.prepareStatement(stride);
preparedStatement.setLong(1, user.getId());
preparedStatement.addBatch();
preparedStatement = connection.prepareStatement(strideLike);
preparedStatement.setLong(1, user.getId());
preparedStatement.addBatch();
preparedStatement = connection.prepareStatement(strideCommentMe);
preparedStatement.setLong(1, user.getId());
preparedStatement.addBatch();
preparedStatement = connection.prepareStatement(strideCommentLike);
preparedStatement.setLong(1, user.getId());
preparedStatement.addBatch();
preparedStatement = connection.prepareStatement(strideCommentFollow);
preparedStatement.setLong(1, user.getId());
preparedStatement.addBatch();
preparedStatement.executeBatch();
connection.commit();
}
catch(NamingException error)
{
System.out.println("NotificationsDAO - resetNotifications() - Error With JNDI Lookup - " + error.getMessage());
error.printStackTrace();
}
catch(SQLException error)
{
System.out.println("NotificationsDAO - resetNotifications() - Error With SQL - " + error.getMessage());
error.printStackTrace();
}
finally
{
if (initialContext != null) try{initialContext.close();} catch(NamingException ignore) {}
if (environmentContext != null) try{environmentContext.close();} catch(NamingException ignore) {}
if (connection != null) try{connection.close();} catch(SQLException ignore) {}
if (preparedStatement != null) try{preparedStatement.close();} catch(SQLException ignore) {}
}
}