The following is sql code which checks for multiple �titles� with the same value (less than or equal to 3)
"SELECT count(*)<=3 FROM module WHERE title='?'".
I am trying to write a snippet of code that does a select count(*) from module where title=? (above code), and then if the result of that is 3=3 then do the INSERT (following code) else display an error message without inserting the record.
In simple terms the following code should only execute if the above code is true, else display a message without saving. can someone please help me out as I am kind of stuck.
PreparedStatement new_module = connection.prepareStatement("INSERT INTO module (room_number, module_code, title, provider, duration, time_slot, weekdays)"+ "VALUES(?,?,?,?,?,?,?)");
new_module.setString(1, request.getParameter("room_number"));
new_module.setString(2, request.getParameter("module_code"));
new_module.setString(3, request.getParameter("title"));
new_module.setString(4, request.getParameter("provider"));
new_module.setInt(5, 1);
new_module.setString(6, request.getParameter("time_slot"));
new_module.setString(7, request.getParameter("weekdays"));
new_module.executeUpdate();
connection.commit();
new_module.close();
response.sendRedirect("index.jsp");
connection.setAutoCommit(savedCommitValue);
}
"SELECT count(*)<=3 FROM module WHERE title='?'".
I am trying to write a snippet of code that does a select count(*) from module where title=? (above code), and then if the result of that is 3=3 then do the INSERT (following code) else display an error message without inserting the record.
In simple terms the following code should only execute if the above code is true, else display a message without saving. can someone please help me out as I am kind of stuck.
PreparedStatement new_module = connection.prepareStatement("INSERT INTO module (room_number, module_code, title, provider, duration, time_slot, weekdays)"+ "VALUES(?,?,?,?,?,?,?)");
new_module.setString(1, request.getParameter("room_number"));
new_module.setString(2, request.getParameter("module_code"));
new_module.setString(3, request.getParameter("title"));
new_module.setString(4, request.getParameter("provider"));
new_module.setInt(5, 1);
new_module.setString(6, request.getParameter("time_slot"));
new_module.setString(7, request.getParameter("weekdays"));
new_module.executeUpdate();
connection.commit();
new_module.close();
response.sendRedirect("index.jsp");
connection.setAutoCommit(savedCommitValue);
}