2011-12-08 1 views

答えて

1

私は以下の例を挙げました。私はこのガイドがあなたを助けると思う。あなたのres/RW/sql.xmlでLink

:あなたのヘルパークラスで

<sql> 
<statement> 
CREATE TABLE IF NOT EXISTS employee (
     _id INTEGER PRIMARY KEY AUTOINCREMENT, 
     firstName VARCHAR(50), 
     lastName VARCHAR(50), 
     title VARCHAR(50), 
     department VARCHAR(50), 
     managerId INTEGER, 
     city VARCHAR(50), 
     officePhone VARCHAR(30), 
     cellPhone VARCHAR(30), 
     email VARCHAR(30), 
     picture VARCHAR(200)) 
</statement> 
<statement>INSERT INTO employee VALUES(1,'Ryan','Howard','Vice President, North East', 'Management', NULL, 'Scranton','570-999-8888','570-999-8887','[email protected]','howard.jpg')</statement> 
<statement>INSERT INTO employee VALUES(2,'Michael','Scott','Regional Manager','Management',1,'Scranton','570-888-9999','570-222-3333','[email protected]','scott.jpg')</statement> 
<statement>INSERT INTO employee VALUES(3,'Dwight','Schrute','Assistant Regional Manager','Management',2,'Scranton','570-444-4444','570-333-3333','[email protected]','schrute.jpg')</statement> 
<statement>INSERT INTO employee VALUES(4,'Jim','Halpert','Assistant Regional Manager','Manage',2,'Scranton','570-222-2121','570-999-1212','[email protected]','halpert.jpg')</statement> 
<statement>INSERT INTO employee VALUES(5,'Pamela','Beesly','Receptionist','',2,'Scranton','570-999-5555','570-999-7474','[email protected]','beesly.jpg')</statement> 
<statement>INSERT INTO employee VALUES(6,'Angela','Martin','Senior Accountant','Accounting',2,'Scranton','570-555-9696','570-999-3232','[email protected]','martin.jpg')</statement> 
<statement>INSERT INTO employee VALUES(7,'Kevin','Malone','Accountant','Accounting',6,'Scranton','570-777-9696','570-111-2525','[email protected]','malone.jpg')</statement> 
<statement>INSERT INTO employee VALUES(8,'Oscar','Martinez','Accountant','Accounting',6,'Scranton','570-321-9999','570-585-3333','[email protected]','martinez.jpg')</statement> 
<statement>INSERT INTO employee VALUES(9,'Creed','Bratton','Quality Assurance','Customer Services',2,'Scranton','570-222-6666','333-8585','[email protected]','bratton.jpg')</statement> 
<statement>INSERT INTO employee VALUES(10,'Andy','Bernard','Sales Director','Sales',2,'Scranton','570-555-0000','570-546-9999','[email protected]','bernard.jpg')</statement> 
<statement>INSERT INTO employee VALUES(11,'Phyllis','Lapin','Sales Representative','Sales',10,'Scranton','570-141-3333','570-888-6666','[email protected]','lapin.jpg')</statement> 
<statement>INSERT INTO employee VALUES(12,'Stanley','Hudson','Sales Representative','Sales',10,'Scranton','570-700-6666','570-777-6666','[email protected]','hudson.jpg')</statement> 
<statement>INSERT INTO employee VALUES(13,'Meredith','Palmer','Supplier Relations','Customer Services',2,'Scranton','570-555-8888','570-777-2222','[email protected]','palmer.jpg')</statement> 
<statement>INSERT INTO employee VALUES(14,'Kelly','Kapoor','Customer Service Rep.','Customer Services',2,'Scranton','570-123-9654','570-125-3666','[email protected]','kapoor.jpg')</statement> 
</sql> 

public void onCreate(SQLiteDatabase db) { 
       String s; 
       try { 
         Toast.makeText(context, "1", 2000).show(); 
         InputStream in = context.getResources().openRawResource(R.raw.sql); 
         DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 
         Document doc = builder.parse(in, null); 
         NodeList statements = doc.getElementsByTagName("statement"); 
         for (int i=0; i<statements.getLength(); i++) { 
           s = statements.item(i).getChildNodes().item(0).getNodeValue(); 
           db.execSQL(s); 
         } 
       } catch (Throwable t) { 
         Toast.makeText(context, t.toString(), 50000).show(); 
       } 
     } 
関連する問題