我使用下面的代码在我的android应用程序中创建数据库。实际上,需要将数据从另一个表复制到此表中。它只复制10868条记录,但原始表格包含24000条记录。允许空值的SQLite数据库
我检查并最终在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);";
是否有任何其他方式允许列接受空值?我真的很困惑
编辑:Android的代码
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();
}
他们*不接受*源码级空值(除主键列,当然),所以问题应该在其他地方(如不正确的处理空值java端) –
我会发布我的android代码 –
我看到你是从HttpPost而不是直接从另一个SQLITE数据库retreiving值。 难道是它们中的空值不在响应中? –