データベースにデータを挿入できないことがあります。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());
}
}
}