If/Else Bedingung:
<%! String driverName = "com.mysql.jdbc.Driver";%>
<%!String url = "jdbc:mysql://localhost:3306/biointeractive";%>
<%!String user = "admin";%>
<%!String psw = "artechsarsi";%>
<%
String id = request.getParameter("gruppeid");
String abteilung = request.getParameter("id");
Statement statement = null;
ResultSet resultSet = null;
Connection con = null;
PreparedStatement ps = null;
try {
Class.forName(driverName);
con = DriverManager.getConnection(url, user, psw);
statement = con.createStatement();
String sql2 = "select abteilungid from gruppeeintrag where abteilungid like '" + abteilung + "'";
resultSet = statement.executeQuery(sql2);
while (resultSet.next()) {
String idabt = resultSet.getString("abteilungid");
if (idabt != null) {
out.print("Diese Abteilung gehört schon einer Gruppe an!");
}
else {
String sql = "Insert gruppeeintrag set gruppeid=?,abteilungid=?";
ps = con.prepareStatement(sql);
ps.setString(1, id);
ps.setString(2, abteilung);
int i = ps.executeUpdate();
if (i > 0) {
response.sendRedirect("close.html");
} else {
out.print("Problem!");
}
}
}
}
catch (SQLException sql2) {
request.setAttribute("error", sql2);
out.println(sql2);
}
Wenn idabt nicht null ist gibt es auch out.print aus, jedoch wenn idapt null ist(else Bedingung) wird der Eintrag in die MySQL DB nicht gemacht und das Fenster bleibt leer, auch wird keine Fehlermeldung in der Konsole ausgegeben!