Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int addCall(defCall def){
- Connection con = null;
- Statement st = null;
- ResultSet rs = null;
- int returnValue = 0;
- try {
- con = DriverManager.getConnection("jdbc:mysql:///forum","root", "secret");
- st = con.createStatement();
- st.executeUpdate("INSERT INTO `forum`.`active_calls` (`defCoord` ,`attCoord` ,`ships` ,`ETA` ,`ID` ,`origETA` ,`needs` ,`bcalc` ,`active`)" +
- "VALUES ('"+def.getDefcoord().asString()+"'" +
- ", '"+def.getAttcoord().asString()+"'" +
- ", '"+def.getShips()+"'" +
- ", '"+def.getETA()+"'" +
- ", NULL " +
- ", '"+def.getOrigETA()+"'" +
- ", '"+def.getNeeds()+"'" +
- ", '"+def.getBcalc()+"'" +
- ", '1');"
- ,Statement.RETURN_GENERATED_KEYS);
- rs = st.getGeneratedKeys();
- rs.next();
- returnValue = rs.getInt(1);
- } catch (SQLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- finally{
- if(rs != null){
- try {
- rs.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if(st != null){
- try {
- st.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if(con != null){
- try {
- con.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- return returnValue;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement