我只想在插入sql查询时使用A
表。
。如果我的A
表有1条记录。执行更新1记录。
我的A
表有0条记录。插入查询。
我知道只使用插入查询。
public class compareInsert extends Thread {
private Connection mConnection = null;
private Statement mStatement = null;
@Override
public void run() {
super.run();
Looper.prepare();
setDB();
Looper.loop();
}
public void setDB() {
mConnection = DBconnect.connectJDBC(); // DB Connect.
try {
mStatement = mConnection.createStatement();
mStatement.executeQuery("use be");
String insertq = "insert into A"
+ "(name, old, num)"
+ "values"
+ "(?, ?, ?);
PreparedStatement statement = mConnect.prepareStatement(insertq);
statement.setString(1, "hyunwook");
statement.setString(2, "17");
statement.setString(3, "2732");
int ret = statement.executeUpdate();
if (ret > 0) {
Log.d(TAG, "SUCCESS");
} else {
Log.d(TAG, "failed");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
mConnection.close();
} catch (Exception e) {
}
}
}
}
此源是插入查询代码。 但应用程序启动,始终插入查询。
请帮帮我
感谢。