public byte auto_to_client_add( int brandID, int modelID, int usrID, String vin, int year, int volume, String gosnomer, String memo) { byte res = 0; Connection connection = null; try { connection = ConnectionHandler.getConnection(); Statement statement = connection.createStatement(); String query; query = "SELECT max(id) FROM `auto_to_client`;"; ResultSet rs = statement.executeQuery(query); rs.first(); int id = rs.getInt("max(id)") + 1; query = "INSERT INTO `javatest`.`auto_to_client` (`id`, `brand_id`, `model_id`, `usr_id`, `vin`, `year`, `volume`, `gosnomer`, `memo`) " + "VALUES (" + id + ", '" + brandID + "', '" + modelID + "', '" + usrID + "', '" + vin + "', '" + year + "', '" + volume + "', '" + gosnomer + "', '" + memo + "');"; if (statement.executeUpdate(query) == 1) res = 1; } catch (Exception e) { e.printStackTrace(); res = 0; } finally { try { ConnectionHandler.closeConnection(connection); } catch (SQLException e) { e.printStackTrace(); } } return res; }
public byte updateInSql() { Connection connection = null; byte res = 0; try { connection = ConnectionHandler.getConnection(); Statement statement = connection.createStatement(); String query; query = "UPDATE `javatest`.`users` SET " + "`name` = '" + name + "', " + "`grp_id` = '" + grpID + "', " + "`phone` = '" + phone + "', " + "`email` = '" + email + "', " + "`shipment` = '" + shipment + "', " + "`ship_tabu` = '" + ship_tabu + "', " + "`memo` = '" + memo + "' " + "WHERE `users`.`id` = " + id + ";"; if (statement.executeUpdate(query) == 1) res = 1; } catch (Exception e) { System.out.println(e.toString()); } finally { try { ConnectionHandler.closeConnection(connection); } catch (SQLException e) { e.printStackTrace(); res = 0; } } return res; }
public byte saveToSql() throws OrderException { byte res = 0; try (Connection connection = ConnectionHandler.getConnection()) { Statement statement = connection.createStatement(); String query; query = "SELECT max(id) FROM `users`;"; ResultSet rs = statement.executeQuery(query); rs.first(); id = rs.getInt("max(id)") + 1; query = "INSERT INTO `javatest`.`users` (`id`, `name`, `grp_id`, `phone`, `email`, `shipment`, `ship_tabu`, `memo`) " + "VALUES (" + id + ", '" + name + "', '" + grpID + "', '" + phone + "', '" + email + "', '" + shipment + "', '" + ship_tabu + "', '" + memo + "');"; if (statement.executeUpdate(query) == 1) res = 1; } catch (SQLException e) { throw new OrderException(e.getMessage(), e); } return res; }