· 8 years ago · Jul 30, 2018, 04:32 PM
1this.insertStmt = this.myDataBase.compileStatement(INSERT);
2
3public void createDynamicDatabase(Context context, String tableName, ArrayList<String> title)
4{
5 Log.i("INSIDE createLoginDatabase() Method","*************creatLoginDatabase*********");
6
7 try
8 {
9 int i;
10 String queryString;
11
12 // Opens database in writable mode.
13 myDataBase = context.openOrCreateDatabase("Db",Context.MODE_WORLD_WRITEABLE, null);
14
15 //System.out.println("Table Name : "+tableName.get(0));
16
17 queryString = title.get(0)+" VARCHAR(30),";
18 Log.d("**createDynamicDatabase", "in oncreate");
19
20 for(i = 1;i < title.size() - 1; i++)
21 {
22 queryString += title.get(i);
23 queryString +=" VARCHAR(30)";
24 queryString +=",";
25 }
26
27 queryString+= title.get(i) +" VARCHAR(30)";
28
29 queryString = "CREATE TABLE IF NOT EXISTS " + tableName + "("+queryString+");";
30
31 System.out.println("Create Table Stmt : "+ queryString);
32
33 myDataBase.execSQL(queryString);
34 }
35 catch (SQLException ex)
36 {
37 Log.i("CreateDB Exception ",ex.getMessage());
38 }
39}
40
41public void insert(Context context, ArrayList<String> array_vals, ArrayList<String> title, String TABLE_NAME)
42{
43 Log.d("Inside Insert","Insertion starts for table name: "+TABLE_NAME);
44
45 // Opens database in writable mode.
46 myDataBase = context.openOrCreateDatabase("Db",Context.MODE_WORLD_WRITEABLE, null);
47
48 String titleString = null;
49 String markString = null;
50
51 int i;
52 titleString = title.get(0)+",";
53 markString = "?,";
54
55 Log.d("**createDynamicDatabase", "in oncreate");
56
57 for(i = 1;i < title.size() - 1; i++)
58 {
59 titleString += title.get(i);
60 titleString +=",";
61 markString += "?,";
62 }
63
64 titleString+= title.get(i);
65 markString += "?";
66
67 //System.out.println("Title String: "+titleString);
68 //System.out.println("Mark String: "+markString);
69
70 INSERT="insert into "+ TABLE_NAME + "("+titleString+")"+ "values" +"("+markString+")";
71 System.out.println("Insert statement: "+INSERT);
72 //System.out.println("Array size iiiiii::: "+array_vals.size());
73 //this.insertStmt = this.myDataBase.compileStatement(INSERT);
74 int s=0;
75
76 while(s<array_vals.size())
77 {
78 System.out.println("Size of array1"+array_vals.size());
79 //System.out.println("Size of array"+title.size());
80 int j=1;
81 this.insertStmt = this.myDataBase.compileStatement(INSERT);
82 for(int k =0;k< title.size();k++)
83 {
84
85 //System.out.println("Value of column "+title+" is "+array_vals.get(k+s));
86 //System.out.println("PRINT S:"+array_vals.get(k+s));
87 System.out.println("BindString: insertStmt.bindString("+j+","+ array_vals.get(k+s)+")");
88 insertStmt.bindString(j, array_vals.get(k+s));
89
90
91
92 j++;
93 }
94
95 s+=title.size();
96
97 }
98 insertStmt.executeInsert();
99 }
100
101android.database.sqlite.SQLiteException: near "08104710280": syntax error (code 1): , while compiling: insert into 08104710280(sender,receiver,msg)values(?,?,?)
102
103this.insertStmt = this.myDataBase.compileStatement(INSERT);