데이터베이스.rawQuery(String sql, String [] selectionArgs)
데이터베이스.execSQL(String sql, Object [] bindArgs)
결과값을 받아와야 하는 경우에 사용한다.
예시: SELECT
@Overridepublic List<Emp> getEmps() { List<Emp> list = new ArrayList<>(); Cursor cursor = null; sqLiteDatabase = dbsqLiteOpenHelper.getReadableDatabase(); String sql = "select emp_id, emp_name, dept_id from emp where emp_id not null and emp_name not null"; try { cursor = sqLiteDatabase.rawQuery(sql, null); cursor.moveToFirst(); int i = 0; if (cursor.getCount() > 0) { for (i = 0; i < cursor.getCount(); i++) { list.add(new Emp(cursor.getString(0), cursor.getString(1), cursor.getString(2))); cursor.moveToNext(); } } } catch (Exception e) { e.printStackTrace(); Log.e("", e.getMessage()); } finally { if (cursor != null) cursor.close(); } return list; }
데이터베이스.execSQL(String sql, Object [] bindArgs)
결과값이 필요없는 경우에 사용한다.
예시: CREATE, INSERT, UPDATE, DELETE, DROP
@Overridepublic OverwiteObject saveSurveyH(SurveyH surveyH, boolean overwrite) { // OverwiteObject overwiteObject = null; SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd"); Date currentTime = new Date(); String time = date.format(currentTime); sqLiteDatabase = dbsqLiteOpenHelper.getReadableDatabase(); String sql = " UPDATE SURVEY_HIS SET DEPT_ID = ? , LOCA_ID = ? , EMP_ID = ? , SURV_STATUS_FLG = ? WHERE PROD_BARCODE = ? "; sqLiteDatabase.execSQL(sql, new String[]{surveyH.getSurvDeptId(), surveyH.getSurvLocaId(), surveyH.getSurvEmpId(), surveyH.getProdStatusFlgId(), surveyH.getProdBarcode()}); return overwiteObject; }
댓글
댓글 쓰기