1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| public int addContact(Contacts contact) {
Connection conn = null;
PreparedStatement stmt = null;
int rs = 0;
int idcontact = new DriverJDBC().setId("Contacts", "idcontact");
String query = "INSERT INTO Contacts (Resellerid,ContactTypeid,Surname,Name"
+ ",Phone,CellPhone,Fax,Email,Compicheid,title,idcontact,positions,LastUpdate,TSA) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,current timestamp,current timestamp)";
try {
conn = init();
stmt = conn.prepareStatement(query);
stmt.setInt(1,contact.getIdReseller());
stmt.setInt(2,contact.getIdContacType());
stmt.setString(3, contact.getSurname());
stmt.setString(4, contact.getName());
stmt.setString(5, contact.getPhone());
stmt.setString(6, contact.getCellPhone());
stmt.setString(7, contact.getFax());
stmt.setString(8, contact.getEmail());
stmt.setInt(9,new UserController().GetUser().getIdCompiche());
stmt.setString(10, contact.getTitle());
stmt.setInt(11,idcontact);
stmt.setString(12,contact.getPosition());
rs = stmt.executeUpdate();
stmt.close();
} catch (SQLException e) {
System.out.println("Requete creation contact incorrecte");
e.printStackTrace();
} catch (ClassNotFoundException cnf) {
System.out.println("La classe du driver jdbc n'a pu etre chargee");
cnf.printStackTrace();
} finally {
try {
conn.close();
} catch (SQLException e) {
}
}
if(rs >= 0){
new SqlInstructionController().addQuery(query);
}
return rs;
} |
Partager