gpt4 book ai didi

java - 从 jTextField Java 获取 SQL 表名称

转载 作者:行者123 更新时间:2023-11-29 19:01:59 27 4
gpt4 key购买 nike

我想知道是否有办法获取输入到名为 jTextField1 的 JTextField 中的数据库表名称。当我尝试时:

String sqlc = "CREATE TABLE IF NOT EXISTS database." +jTextField1.getText()...

它根本不起作用,并且会引发语法错误。它仅适用于 LAN 网络。这是我完整的创建表 SQL 字符串:

String sqlc = "CREATE TABLE IF NOT EXISTS database." +jTextField1.getText() +
"(IDKath INT(11) NOT NULL AUTO_INCREMENT," +"ΕΣΟΔΑ DOUBLE NULL," +
"ΗΜΕΡΟΜΗΝΙΑ DATE NULL," +"IDClea INT(11) NULL," +"PRIMARY KEY (IDKath)," +
"INDEX IDClea_idx (IDClea ASC)," +"CONSTRAINT IDClea" +"FOREIGN KEY (IDClea)" +
" REFERENCES database.cleaning (IDClean)" +" ON DELETE NO ACTION" +" ON UPDATE NO ACTION)";

最佳答案

首先想到...数据库实际上是您尝试在其中创建表的数据库的名称吗?

第二个想法,该表是否已存在于数据库中?

第三个想法,jTextField1.getText();是否真的给了你任何东西或者给了你你所期望的东西?测试一下:

System.out.println(jTextField1.getText());

只是为了好玩,尝试一下这个 SQL 字符串:

String sqlc = "CREATE TABLE [IF NOT EXISTS] database." + jTextField1.getText() + 
" (IDKath INT(11) NOT NULL AUTO_INCREMENT, ΕΣΟΔΑ DOUBLE [DEFAULT NULL]," +
" ΗΜΕΡΟΜΗΝΙΑ DATE [DEFAULT NULL], IDClea INT(11) [DEFAULT NULL]," +
" PRIMARY KEY (IDKath), INDEX IDClea_idx (IDClea ASC)," + " [CONSTRAINT [IDClea]]" +
" FOREIGN KEY [IDClea_idx] (IDClea)" + " REFERENCES database.cleaning (IDClean)" +
" [ON DELETE NO ACTION] [ON UPDATE NO ACTION])Engine=InnoDB;";

关于java - 从 jTextField Java 获取 SQL 表名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43803156/

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