?? deletedata.java
字號:
package dbconnect;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class DeleteData {
/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
// TODO 自動生成方法存根
PreparedStatement ps;
String sqlString;
String name;
int k;
DbConnect dbcon=new DbConnect();
dbcon.connect();
name = getInput("請輸入待刪除的用戶名:");
sqlString = "delete from result where name='"+name+"'";
ps = (dbcon.getConnction()).prepareStatement(sqlString);
k=ps.executeUpdate(sqlString);
System.out.println("刪除了"+k+"條記錄");
//ps.executeUpdate();
System.out.println("刪除成功!");
if (dbcon.getConnction() == null) {
System.out.println("數據庫連接失敗");
} else
System.out.println("數據庫連接成功");
dbcon.disconnect();
}
public static String getInput(String msg) {
String result = null;
try {
// 創建用戶輸入流
BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
System.out.print(msg);
result = in.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -