Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void insert(ArrayList<Double> list, String tableName, int id)
- throws FileNotFoundException, SQLException {
- // *********update
- // test if the given id is already in the table or not
- String retrievalSql = "SELECT `object` FROM `" + tableName
- + "` where `id` = " + id;
- pst = conn.prepareStatement(retrievalSql);
- ResultSet result = (ResultSet) pst.executeQuery();
- // the result set is not empty
- if (result.next() == true) {
- // return and don't try to insert
- System.out.println("Already exists");
- return;
- }
- // ******************
- String fileName = "list.bin";
- save2(list, fileName);
- String sql = "INSERT INTO `" + tableName
- + "` (`id`, `object`) VALUES (" + id + ",?)";
- // System.out.println(sql);
- // same the arrayList to the file
- save2(list, fileName);
- // read the object from the file
- File file = new File(fileName);
- FileInputStream fin = new FileInputStream(file);
- // STEP 4: Execute a query
- // System.out.println("Creating statement...");
- pst = conn.prepareStatement(sql);
- pst.setBinaryStream(1, fin, (int) file.length());
- pst.executeUpdate();
- // System.out.println("Insertion Done!");
- }
- public void dropTable(String tableName) throws SQLException {
- String query = "DROP table `" + tableName + "`";
- pst = conn.prepareStatement(query);
- System.out.println(query);
- if (pst.execute())
- System.out.println("Table droped successfully");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement