我使用以下代码在我的 android 应用程序中创建数据库。实际上,需要将数据从另一个表复制到该表。它只复制了 10868 条记录,但原始表包含 24000 条记录。
我查了一下,最后发现在 10869 记录处,其中一个字段有一个空值。但是我在创建表的过程中没有指定“not null”。但是这个表不能接受空值。
private static final String SCRIPT_CREATE_DATABASE1 =
"create table " + MYDATABASE_TABLE2 + " ("
+ KEY_ID + " integer primary key autoincrement, "
+ KEY_RCODE + " text, "
+ KEY_RNAME + " text);";
还有其他方法可以让列接受空值吗?我真的很困惑
编辑:安卓代码
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://moberp.svsugar.com:8080/androidservlt/ryotmas");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Toast.makeText(getBaseContext(), "Buffer Error"+"Error converting result"+e.toString(), Toast.LENGTH_LONG).show();
}
try {
jObj = new JSONObject(json);
contacts = jObj.getJSONArray("get");
for(int i = 0; i < contacts.length(); i++){
JSONObject c = contacts.getJSONObject(i);
rcode = c.getString("rcode");
rname = c.getString("rname");
radapter.insert(rcode, rname);
}
Toast.makeText(getBaseContext(), " Ryot BackUp completed", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
Toast.makeText(getBaseContext(), "Error"+e.toString(), Toast.LENGTH_LONG).show();
}