有时我无法将数据插入我的数据库。out of memory
即使 db 文件为空,我也会遇到异常。
以下是我的代码,请看一下。在此先感谢您的任何建议。
public class ThreeptalkDAO {
private static ThreeptalkDAO service;
private static Database database;
public static ThreeptalkDAO getInstance() throws CustomException {
if (service == null) {
service = new ThreeptalkDAO();
URI uri;
try {
uri = URI
.create("file:///SDCard/threeptalk/db/threeptalkdao.db");
database = DatabaseFactory.openOrCreate(uri);
// createMessagesTable();
} catch (Exception e) {
System.out.println("exp is:" + e.getMessage());
Dialog.alert(e + e.getMessage());
throw new CustomException(e.getMessage());
} // here path is like
// 'file:///SDCard/Databases/mytestApp/testdatabase.db'
}
return service;
}
public void createMessagesTable() throws CustomException {
try {
Statement statement = database
.createStatement("CREATE TABLE IF NOT EXISTS messages(message_id INTEGER PRIMARY KEY,message,status,message_type_id,response,date_added,sender,office,sent_on,phoneno)");
statement.prepare();
statement.execute();
statement.close();
} catch (DatabaseException e) {
// TODO Auto-generated catch block
throw new CustomException(e.getMessage());
}
}
public void insertMessages(Vector messages) throws CustomException {
for (int i = 0; i < messages.size(); i++) {
Messages m = (Messages) messages.elementAt(i);
try {
Statement statement = database
.createStatement("INSERT INTO messages (message_id,message,status,message_type_id, response,date_added,sender,office,sent_on,phoneno) VALUES ("
+ m.getMessageID()
+ ",'"
+ m.getMessage()
+ "','"
+ "unread"
+ "','"
+ m.getMessageType()
+ "','"
+ "0"
+ "','"
+ m.getMdate()
+ "','"
+ m.getSender()
+ "','"
+ m.getOffice()
+ "','"
+ m.getSentOn()
+ "','"
+ WebserviceFactory.getInstance().getPhoneNo()
+ "')");
statement.prepare();
statement.execute();
statement.close();
} catch (DatabaseException e) {
// TODO Auto-generated catch block
throw new CustomException(e.getMessage());
}
}
}