Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. public static int addCall(defCall def){
  2.         Connection con = null;
  3.         Statement st = null;
  4.         ResultSet rs = null;
  5.         int returnValue = 0;
  6.         try {
  7.             con = DriverManager.getConnection("jdbc:mysql:///forum","root", "secret");
  8.             st = con.createStatement();
  9.             st.executeUpdate("INSERT INTO `forum`.`active_calls` (`defCoord` ,`attCoord` ,`ships` ,`ETA` ,`ID` ,`origETA` ,`needs` ,`bcalc` ,`active`)" +
  10.                     "VALUES ('"+def.getDefcoord().asString()+"'" +
  11.                     ", '"+def.getAttcoord().asString()+"'" +
  12.                     ", '"+def.getShips()+"'" +
  13.                     ", '"+def.getETA()+"'" +
  14.                     ", NULL " +
  15.                     ", '"+def.getOrigETA()+"'" +
  16.                     ", '"+def.getNeeds()+"'" +
  17.                     ", '"+def.getBcalc()+"'" +
  18.                     ", '1');"
  19.                     ,Statement.RETURN_GENERATED_KEYS);
  20.             rs = st.getGeneratedKeys();
  21.             rs.next();
  22.             returnValue = rs.getInt(1);
  23.         } catch (SQLException e1) {
  24.             // TODO Auto-generated catch block
  25.             e1.printStackTrace();
  26.         }
  27.         finally{
  28.             if(rs != null){
  29.                 try {
  30.                     rs.close();
  31.                 } catch (SQLException e) {
  32.                     // TODO Auto-generated catch block
  33.                     e.printStackTrace();
  34.                 }
  35.             }
  36.             if(st != null){
  37.                 try {
  38.                     st.close();
  39.                 } catch (SQLException e) {
  40.                     // TODO Auto-generated catch block
  41.                     e.printStackTrace();
  42.                 }
  43.             }
  44.             if(con != null){
  45.                 try {
  46.                     con.close();
  47.                 } catch (SQLException e) {
  48.                     // TODO Auto-generated catch block
  49.                     e.printStackTrace();
  50.                 }
  51.             }
  52.                
  53.         }
  54.         return returnValue;
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement