我正在做一个关于用户帐户创建的Java程序,我想检查是否有任何用户名或密码之前在表中。
String kullanici_adi = KullaniciAdi.getText();
String sifre = Sifre.getText();
String query = "CREATE DATABASE IF NOT EXISTS BUTTERFLYFLY";
Statement SQL=null;
Statement SQLD=null;
String yol="jdbc:mysql://localhost:3306/";
String yol2="jdbc:mysql://localhost:3306/butterflyfly";
try {
Connection con= DriverManager.getConnection(yol, "root", "");
SQL = con.createStatement();
SQL.close();
con.close();
Connection cond=DriverManager.getConnection(yol2, "root", "");
Main m=new Main();
String x=m.oturum_kurulumu;
SQLD= cond.createStatement();
SQLD.executeUpdate(x);
/* If there is a username or password in table pass this
PreparedStatement stmt = cond.prepareStatement("INSERT INTO Oturum (Kullanici_Adi, Sifre)\n" +
"VALUES (?, ?);");
stmt.setString(1, kullanici_adi);
stmt.setString(2, sifre);
stmt.executeUpdate();
*/
} catch (SQLException e) {
System.out.println("Bir hata olustu");
System.out.println(e.getMessage());
}
字符串
我想在表中检测值,我研究了一下,我刚刚发现检查特定值,如 SELECT numR FROM reference
WHERE numR =“x”
但我想检查只是如果有一个表上的任何值通过代码
1条答案
按热度按时间7hiiyaii1#
当你在
Kullanici_Adi
上创建一个唯一的密钥时:字符串
要替换现有密码,请执行以下操作:
型
ref用于验证重复密钥更新。
如果您想保留现有值:
型
ref表示忽略。
两个语句中受影响的行将指示是否存在现有行。
“check”的问题是它受到竞争条件的影响,另一个web查询可能会在检查和你选择对表采取的任何操作之间运行。所以在编写数据库代码时,考虑竞争条件并执行这些原子性(或在事务中)。