gpt4 book ai didi

java - 无法将 UUID 插入嵌入式数据库

转载 作者:行者123 更新时间:2023-12-02 10:10:30 24 4
gpt4 key购买 nike

我一直在尝试将数据从应用程序插入数据库,但总是遇到与 UUID 编号相关的语法错误,该编号将成为客户的 ID 和表的主键。该列设置为 BIGINT ,它总是返回。这是代码:

String a = txtNombre.getText();
String b = txtApellido.getText();
String c = txtLetras.getText();
String d = txtFin.getText();
String e = txtMensual.getText();
e = e.replaceAll("[^\\d.]","");
String f = txtfecha.getText();
String g = txtdeuda.getText();
g = g.replaceAll("[^\\d.]","");
int c1 = Integer.parseInt(c);
long result = UUID.nameUUIDFromBytes((a+b).getBytes()).getMostSignificantBits();
String x = "" + result + "";
String sbStr = x.substring(0, 6);
sbStr = sbStr.replaceAll("[^\\d.]","");
long csId = Long.parseLong(sbStr);
JOptionPane.showInternalMessageDialog(dskPane, "Cliente Ingresado con id#" + csId, "Cliente a Base de"
+ "Datos", 1, null);
connectMyDB con = new connectMyDB();
Statement state = null;

try {
Connection charlie = con.connect();
state = charlie.createStatement();
String insert = "insert into APP.CLIENTES("+csId+",'"+a+"',"
+ "'"+b+"',"+c1+","+d+","+e+",'"+f+"',"+g+")";
state.executeUpdate(insert);
System.out.println(insert);
if(state!=null) {
state.close();
charlie.close();
}
} catch(SQLException ex) {
System.out.print(ex);
}

我总是得到sql.SQLSyntaxErrorException: Syntax error: Encountered "61297" at line 1, column 26 。有没有办法避免这种情况?

最佳答案

插入 SQL 命令的正确方法之一是: insert into tables <strong>values</strong> (val1, val2, ...)

此外,您还必须使用PreparedStatement来防止SQL注入(inject)。

关于java - 无法将 UUID 插入嵌入式数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55030279/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com