addAnswer
This commit is contained in:
parent
9a92ea66b3
commit
213a8c6571
3 changed files with 24 additions and 5 deletions
|
@ -51,16 +51,25 @@ public class Database implements AutoCloseable {
|
|||
// Using the try-with-resources syntax, this will call ps.close() automatically
|
||||
}
|
||||
|
||||
public boolean addAnswer(String name, int answerOne, int answerTwo, int answerThree, int answerFour) {
|
||||
public boolean addAnswer(String name, String answerOne, String answerTwo, String answerThree, String answerFour) {
|
||||
String sql = "insert into Answer (answerOne, answerTwo, answerThree, answerFour, name) values(?,?,?,?,?)";
|
||||
|
||||
try(PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
return false;
|
||||
ps.setString(1, answerOne);
|
||||
ps.setString(2, answerTwo);
|
||||
ps.setString(3, answerThree);
|
||||
ps.setString(4, answerFour);
|
||||
ps.setString(5, name);
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
if(e.getErrorCode()==1062 && e.getSQLState().equals("23000")) {
|
||||
// duplicate key error
|
||||
System.out.println(name + " already exists in the database");
|
||||
} else {
|
||||
printSqlError(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,14 @@ public class Dump extends HttpServlet {
|
|||
return value > 0 && value <11;
|
||||
}
|
||||
|
||||
/// Write fn that takes params and inputs to db, returns true if succ else false if fail
|
||||
// test(str a, str b, str c)
|
||||
protected boolean updateAnswers(String answerOne, String answerTwo) (
|
||||
/// logic
|
||||
|
||||
return true;
|
||||
)
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
|
|
|
@ -113,6 +113,8 @@ public class Survey extends HttpServlet {
|
|||
s12 = Integer.parseInt(s12String);
|
||||
s13 = Integer.parseInt(s13String);
|
||||
s14 = Integer.parseInt(s14String);
|
||||
|
||||
String str = s11String+s12String+s13String;
|
||||
} catch (NumberFormatException e) {
|
||||
valuesOk = false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue