2016-08-04 7 views
0

나는 안드로이드 애플 리케이션을 만들고있다. 일부 로컬 파일 (HTML)을 만들어 WebView에 표시해야하지만 로컬 데이터베이스가 필요합니다. SqlLite를 WebView에 통합 할 수 있습니까? 아니면 그냥 대안을 사용 하시겠습니까? 감사합니다. . 1.First 모든WebView의 SqlLite

+0

일부 로컬 파일 HTML 저장 SQLite를 사용 하시겠습니까? – sonnv1368

+0

아니요, 일부 데이터를 저장해야합니다. 그런 다음 HTML 파일에서 데이터를 추가, 편집 및 삭제할 수 있어야합니다. –

답변

0

는 클래스 SQLiteOpenHelper

2.Create에게 계약을 연장하고 필요한 모든 기능을 구현하는 클래스를 만든다. 방법에서 onCreate ((SQLiteDatabasedb)

그냥 문자열 쿼리라는 만들고 원하는 테이블을 생성에

및 에는 ExecSQL 그 예를 들면 다음과 같습니다

문자열 쿼리 =하지 테이블을 존재하는 경우 "테이블을 생성 (텍스트 텍스트, 이름 텍스트 2, _id 텍스트) "; db.execSQL (쿼리) 그런 다음 SQL 라이트 사용에 새로운 행을 작성을 위해 :

public void add_new_row(String text,String text2,String _id){ try{ 
ContentValues cn=new ContentValues(); cn.put("text",per_name); 
cn.put("text2",per_age);  cn.put("_id",per_age);  

SQLiteDatabase db;  db=getWritableDatabase(); 
db.insert("table",null,cn);} catch(Exception e){ 
Log.i("AddSql_lite","Print :"+e.to); 

} And for read Row from sqllite you just use : 

public String getRow_by_id(String _id){ string text = ""; try{ 
    db=getWritableDatabase(); query="select * from table where _id = 
    '"+_id+"'"; 

    Cursor cr=db.rawQuery(query, null); 
    if(cr.moveToFirst()){ 
     do{ 
      text = cr.getString(0); 
      String text2 = cr.getString(1); 
      String _id = cr.getString(2); 
     }while(cr.moveToNext()); 
    } 

}catch(Exception e){ 
} 

return text; } And for reading all the rows in the table one after another : 

public int get_all_Rows(){ string int counter = 0; try{ 
db=getWritableDatabase(); query="select * from table"; 

    Cursor cr=db.rawQuery(query, null); 
    if(cr.moveToFirst()){ 
     do{ 
      text = cr.getString(0); 
      String text2 = cr.getString(1); 
      String _id = cr.getString(2); 
      counter++; 
     }while(cr.moveToNext()); 
    } 

}catch(Exception e){ 
} 

return counter; } Hope its will help you to understand how Sqllite work and how build it correctly :) 

그리고 그것을 위해 그냥 실행하십시오 :

SQLiteDataBase Sqllite_ref = new SQLiteDataBase(context, "VerName", 
null, 1); 

Sqllite_ref.add_new_row("hey","hey4","1"); 
Sqllite_ref.add_new_row("hey2","hey5","2"); 
Sqllite_ref.add_new_row("hey3","hey6","3"); 

Sqllite_ref.getRow_by_id("2");>>> will return "hey2" 
Sqllite_ref.get_all_Rows()>>> will return 3 [number of items you have 
in the sqllite]