/** * 查询申成知道提问 * * @param question * @return */ public static List<CloudKnowAsk> queryCloudKnowAsksByQuestion(String question) throws Exception { List<CloudKnowAsk> list = new ArrayList<CloudKnowAsk>(); String sql = "SELECT id,user_id,question,description,type,urgent,state," + "create_date,create_time,create_ip,update_date,update_time,update_ip FROM" + " cloud_know_ask WHERE question like '%" + question + "%' ORDER BY id DESC"; // AND state=" + STATE_NORMAL +" 前面有or这里用and好像无效 Connection c = DB.getConn(); Statement stmt = DB.createStatement(c); ResultSet rs = DB.executeQuery(c, stmt, sql); try { if (rs == null) { throw new RuntimeException("数据库操作出错,请重试!"); } while (rs.next()) { int id = rs.getInt("id"); int userId = rs.getInt("user_id"); String newQuestion = rs.getString("question"); String description = rs.getString("description"); String type = rs.getString("type"); int urgent = rs.getInt("urgent"); int state = rs.getInt("state"); String createDate = rs.getString("create_date"); String createTime = rs.getString("create_time"); String createIp = rs.getString("create_ip"); String updateDate = rs.getString("update_date"); String updateTime = rs.getString("update_time"); String updateIp = rs.getString("update_ip"); /** SQL 语句总 AND state=" + STATE_NORMAL +" 前面有or这里用and好像无效 */ if (state != STATE_NORMAL) { continue; } CloudKnowAsk cloudKnowAsk = new CloudKnowAsk( id, userId, newQuestion, description, type, urgent, state, createDate, createTime, createIp, updateDate, updateTime, updateIp); list.add(cloudKnowAsk); } return list; } finally { DB.close(rs); DB.close(stmt); DB.close(c); } }
/** * 根据id查申成知道提问 * * @param id * @return * @throws Exception */ public static CloudKnowAsk getCloudKnowAskById(int id) throws Exception { CloudKnowAsk cloudKnowAsk = null; String sql = "SELECT id,user_id,question,description,type,urgent,state,create_date,create_time," + "create_ip,update_date,update_time,update_ip FROM cloud_know_ask WHERE id=" + id; Connection c = DB.getConn(); Statement stmt = DB.createStatement(c); ResultSet rs = DB.executeQuery(c, stmt, sql); try { if (rs == null) { throw new RuntimeException("数据库操作出错,请重试!"); } while (rs.next()) { int userId = rs.getInt("user_id"); String question = rs.getString("question"); String description = rs.getString("description"); String type = rs.getString("type"); int urgent = rs.getInt("urgent"); int state = rs.getInt("state"); String createDate = rs.getString("create_date"); String createTime = rs.getString("create_time"); String createIp = rs.getString("create_ip"); String updateDate = rs.getString("update_date"); String updateTime = rs.getString("update_time"); String updateIp = rs.getString("update_ip"); cloudKnowAsk = new CloudKnowAsk( id, userId, question, description, type, urgent, state, createDate, createTime, createIp, updateDate, updateTime, updateIp); } return cloudKnowAsk; } finally { DB.close(rs); DB.close(stmt); DB.close(c); } }
/** * 根据用户id查最大的申成知道提问Id * * @param userId * @return * @throws Exception */ public static int getMaxIdByUserId(int userId) throws Exception { String sql = "SELECT MAX(id) max_id FROM cloud_know_ask WHERE user_id=" + userId; Connection c = DB.getConn(); Statement stmt = DB.createStatement(c); ResultSet rs = DB.executeQuery(c, stmt, sql); try { if (rs == null) { throw new RuntimeException("数据库操作出错,请重试!"); } while (rs.next()) { return rs.getInt("max_id"); } return 0; } finally { DB.close(rs); DB.close(stmt); DB.close(c); } }
public void save() { boolean isNoticed = false; if (!notice.isVisible()) { isNoticed = true; notice.setVisible(true); notice.setText("Saving..."); } if (getOptions() != null) { DB database = null; try { database = factory.open(this.leveldbStore.getSelectedFile(), getOptions()); DBIterator iterator = database.iterator(); HashSet<byte[]> keys = new HashSet<>(); for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) { keys.add(iterator.peekNext().getKey()); } iterator.close(); for (byte[] key : keys) { database.delete(key); } for (int i = 0; i < dataList.getModel().getSize(); ++i) { DBItem item = dataList.getModel().getElementAt(i); database.put(item.key, item.value); } } catch (Exception e) { JOptionPane.showMessageDialog(pane, "Unable to open database:\n" + e); e.printStackTrace(); } finally { if (database != null) { try { database.close(); } catch (IOException e) { JOptionPane.showMessageDialog(pane, "Unable to close database:\n" + e); e.printStackTrace(); } } saveButton.setEnabled(false); } } if (isNoticed) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } notice.setVisible(false); notice.setText(""); } }
public void close() throws IOException { if (!readOnly) { LOG.info("Compacting leveldb"); String stats = db.getProperty("leveldb.stats"); LOG.info(stats); ((JniDB) db).compactRange(null, null); LOG.info("Done compacting leveldb"); stats = db.getProperty("leveldb.stats"); LOG.info(stats); } db.close(); }
public void onAdd(View v) { ContentValues cv = new ContentValues(); String nsStr = ns.getText().toString(); String pocStr = poc.getText().toString(); SQLiteDatabase db = dbHelper.getWritableDatabase(); Log.d(LOG_TAG, "--- Insert in mytable: ---"); cv.put(dbHelper.NAME_SURNAME, nsStr); cv.put(dbHelper.POCITON, pocStr); cv.put(dbHelper.ID_MG, mgId); long rowID = db.insert(dbHelper.TABLE_EM, null, cv); dbHelper.close(); Log.d(LOG_TAG, "row inserted, ID = " + rowID); finish(); }
public static void main(String[] args) throws IOException { DB db = new DB(); if (!db.open(file, DB.OWRITER | DB.OCREATE)) { System.err.println("open error: " + db.error()); return; } long tm = System.currentTimeMillis(); for (int i = 0; i < RECORDS; i++) { if (i % 10000 == 0) { // myDatabase.sync(); System.out.println( "Rec " + i + " (" + (i * 1000.0 / (System.currentTimeMillis() - tm)) + "rec/s)"); } byte[] theKey = ("key" + i).getBytes(); Camera p = new Camera(); p.setCity("city" + i); p.setCountry("country" + (i / 100)); for (int j = 1; j <= nRec; j++) { LogRecord lr = new LogRecord(); lr.setTime(1111); lr.setEventHash("hash-" + i + "-" + j); p.addLogRecord(lr); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(p); oos.close(); db.set(theKey, baos.toByteArray()); } if (!db.close()) { System.err.println("close error: " + db.error()); } }
public void Calc() { // calculates the balance deducting the fare int Result = rtnBalance - fare; String date = bcheckTime(); // get current time DB data = new DB(this); // opens the database data.open(); data.updateBal(Result, date); // calls the update balance function of // the database data.close(); updateWidget(); // moves to main screen Intent i = new Intent(this, Main.class); startActivity(i); finish(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // открываем подключение к БД db = new DB(this); db.open(); // получаем курсор cursor = db.getAllData(); if (cursor.getCount() == 0) { fillData(); cursor = db.getAllData(); } startManagingCursor(cursor); lvData = (ListView) findViewById(R.id.listView1); cursor.moveToFirst(); itemArray = new ArrayList<String>(); Bitmap bitmap = null; for (int i = 0; i < cursor.getColumnCount(); i++) { if (!cursor.getColumnName(i).equals(DB.COLUMN_FOTO)) { itemArray.add(cursor.getString(i)); } else { bitmap = byteToImage(cursor.getBlob(i)); } } itemAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, itemArray); db.close(); ImageView ivFoto = new ImageView(this); if (bitmap != null) { ivFoto.setImageBitmap(bitmap); } lvData.addFooterView(ivFoto); lvData.setAdapter(itemAdapter); }
public void delete(byte[] key) { if (getOptions() != null) { DB database = null; try { database = factory.open(this.leveldbStore.getSelectedFile(), getOptions()); database.delete(key); } catch (Exception e) { JOptionPane.showMessageDialog(pane, "Unable to open database:\n" + e); e.printStackTrace(); } finally { if (database != null) { try { database.close(); } catch (IOException e) { JOptionPane.showMessageDialog(pane, "Unable to close database:\n" + e); e.printStackTrace(); } } } } }
public void test_issue_17_double_concurrent_get() throws InterruptedException { final DB db = DBMaker.openFile(newTestFile()).disableTransactions().disableCache().make(); db.createHashMap("map"); class RR implements Runnable { public void run() { Map<Integer, String> m = db.getHashMap("map"); for (int i = 1; i < 10000; i++) m.put(i, "-" + i); } } Thread thread = new Thread(new RR()); thread.start(); new RR().run(); thread.join(); db.close(); }
public void close() { underlying.close(); }
/** Az alkalmazás befejezése, erőforrások felszabadítása. */ public static void exitGame() { DB.close(); System.exit(0); }
protected void onDestroy() { super.onDestroy(); db.close(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setScreen(); getprefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); editor = getprefs.edit(); child = getprefs.getBoolean("chld", false); student = getprefs.getBoolean("schld", false); Gaeilge = getprefs.getBoolean("irish", false); logged = getprefs.getBoolean("logged", false); user = getprefs.getString("user", null); DB data = new DB(this); data.open(); rtnBalance = data.getBalance(); data.close(); /* * Below is an array of fares for each type of trip, here an array is * used as these fares may change */ // bus fares bus = new int[] {55, 140, 190, 210, 245}; // standard cbus = new int[] {50, 90, 90, 110, 110}; // child fare sbus = new int[] {50, 70, 70, 70, 70}; // school child // express bus fares expbus = new int[] {290, 400}; cexpbus = new int[] {190, 220}; // luas red line fares luasR = new int[] {145, 175, 205, 225, 240}; cluasR = new int[] {80, 80, 80, 100, 100}; sluasR = new int[] {80, 80, 80, 100, 100}; // luas green line fares luasG = new int[] {145, 180, 215, 235, 250}; cluasG = new int[] {80, 80, 80, 100, 100}; sluasG = new int[] {80, 80, 80, 100, 100}; // train fares train = new int[] {135, 165, 195, 230, 275, 330, 435}; ctrain = new int[] {80, 80, 115, 115, 130, 130, 175}; strain = new int[] {70, 70, 70, 70, 70, 70, 70}; checkTime(); // calls the check time method from below /* This code checks the string variable sent from previous activity */ Intent input = getIntent(); Bundle b = input.getExtras(); if (b != null) { tripType = (String) b.get("Type"); } if (tripType.equals("Bus")) { setContentView(R.layout.addbus); // sets content view to the addbus // layout setupBus(); // calls the setupBus method from below } else if (tripType.equals("ExpBus")) { setContentView(R.layout.addexpbus); // sets content view to the // addbus // layout setupExpBus(); // calls the setupBus method from below } else if (tripType.equals("Train")) { setContentView(R.layout.addtrain); // sets content view to the // addtrain layout setupTrain(); } else if (tripType.equals("LuasG")) { setContentView(R.layout.addluasg); // sets content view to the // addluasg layout setupLuasG(); } else if (tripType.equals("LuasR")) { setContentView(R.layout.addluasr); // sets content view to the // addluasr layout setupLuasR(); } }
public void close() { underlying.close(); Orient.instance().getDatabaseFactory().unregister(databaseOwner); }
@Override public void onDestroy() { super.onDestroy(); db.close(); }
public void openDatabase(File select) { if (getOptions() != null) { DB database = null; try { database = factory.open(select, getOptions()); DBIterator iterator = database.iterator(); ArrayList<DBItem> data = new ArrayList<>(); String reg = findField.getText().trim(); for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) { if (reg.isEmpty() || new BigInteger(iterator.peekNext().getKey()).toString(16).contains(reg) || LevelDBViewer.toHexString(iterator.peekNext().getKey()).contains(reg) || new BigInteger(iterator.peekNext().getValue()).toString(16).contains(reg) || LevelDBViewer.toHexString(iterator.peekNext().getValue()).contains(reg) || new String(iterator.peekNext().getKey()).contains(reg) || new String(iterator.peekNext().getValue()).contains(reg)) { data.add(new DBItem(iterator.peekNext().getKey(), iterator.peekNext().getValue())); } } iterator.close(); dialog.getRootPane().setDefaultButton(putButton); dataList.getSelectionModel().clearSelection(); dataList.setListData(data.toArray(new DBItem[data.size()])); putButton.setEnabled(true); key.setEnabled(true); value.setEnabled(true); findField.setEnabled(true); deleteButton.setEnabled(true); putType.setEnabled(true); signedBox.setEnabled(true); // saveButton.setEnabled(true); hexValue.setText(""); stringValue.setText(""); hexKey.setText(""); stringKey.setText(""); lengthLabel.setText(""); keyLength.setText(""); valueLength.setText(""); } catch (Exception e) { JOptionPane.showMessageDialog(pane, "Unable to open database:\n" + e); e.printStackTrace(); } finally { if (database != null) { try { database.close(); } catch (IOException e) { JOptionPane.showMessageDialog(pane, "Unable to close database:\n" + e); e.printStackTrace(); } } } } }
/** * Tears down the fixture, for example, close a network connection. This method is called after a * test is executed. */ public void tearDown() throws Exception { db.close(); super.tearDown(); }