我是Java的新手,我刚刚在StackOverflow中找到了这段代码:ResizeTextArea.
我想用JTextPane而不是JTextArea.在JTextPane,没有setRows()方法可以改变行数.任何帮助,将不胜感激.
以下方法我想同时插入几个记录.
public void insert() {
try {
this.connection.setAutoCommit(false);
PreparedStatement ps = this.connection.prepareStatement(
"INSERT INTO COMPANY (NAME,Address) Values (?,?)", new String[]{"ID"});
ps.setString(1, "X01");
ps.setString(2, "Address1");
ps.addBatch();
ps.setString(1, "Y01");
ps.setString(2, "Address2");
ps.addBatch();
//EXCEPTION OCCURS HERE
int[] numUpdates = ps.executeBatch();
for (int i = 0; i < numUpdates.length; i++) {
System.out.println("Execution " + i +
"successful: " + numUpdates[i] + " rows inserted");
}
ResultSet resultSet =
(ps).getGeneratedKeys();
while (resultSet.next()) {
String deptNoKey = resultSet.getString(1);
System.out.println("Automatically generated key value = "
+ deptNoKey); …Run Code Online (Sandbox Code Playgroud) 给出以下代码:
sqLiteDatabase.execSQL("create table if not exists ACCOUNT (ID integer primary key autoincrement," +
"CASH LONG NOT NULL," +
"BANKID INTEGER NOT NULL," +
"ACCOUNTNO TEXT ," +
"DATE TEXT NOT NULL," +
"COMMENT TEXT);");
Run Code Online (Sandbox Code Playgroud)
在SQLite中创建一个表.
添加记录后如何获取lastID?
使用以下代码:
contentValues.put("CASH", accountTO.getCash());
contentValues.put("DATA", DatePro.currentDate());
contentValues.put("BANKID", accountTO.getBankID());
contentValues.put("ACCOUNTNO", accountTO.getAccountNo());
contentValues.put("COMMENT", accountTO.getComment());
Long i = sqLiteDatabase.insert("ACCOUNT", null, contentValues);
Run Code Online (Sandbox Code Playgroud)
我得到-1.