gpt4 book ai didi

Java sql 插入 JOptionpane

转载 作者:行者123 更新时间:2023-11-29 19:04:57 25 4
gpt4 key购买 nike

尝试用 Java 将单行插入数据库。它只插入第一列,我不知道为什么。这是代码:

@Override
public void actionPerformed(ActionEvent e) {
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
int x = 1;
int limit;
//promts the user to enter input
// String InputString = JOptionPane.showInputDialog(null, "Enter the Number of Countries: ",JOptionPane.QUESTION_MESSAGE);
// limit = Integer.parseInt(InputString);

Connection connection;
PreparedStatement ps;
try {
String dbName = "osdesign";
String dbUserName = "root";
String dbPassword = "";
//String u = jtfuser.getText();
//String p =jpfpass.getName();
String connectionString = "jdbc:mysql://localhost/" + dbName + "?user="
+ dbUserName + "&password=" + dbPassword
+ "&useUnicode=true&characterEncoding=UTF-8";
connection = DriverManager.getConnection(connectionString);
JOptionPane.showMessageDialog(null, "Connected!");

//int x = 1;
User List = new User();

//User[] List = new User [limit];
//String query;
//for (x = 0; x < limit; x++)
// {
///List[x] = new User();
//List[x].User_type = null;
List.input(x);
//String sql = "INSERT into `userlist` (`UsrCode`, `UsrName`, `UsrPass`, `UsrPassChgDays`, `UsrPassChgDate`, `Usrtype`) VALUES( ?, ?, ?, ?, ?, ?);";

PreparedStatement preparedStmt = connection.prepareStatement("INSERT INTO `userlist`" +
"VALUES( ?, ?, ?, ?, ?, ?);");

String ID = List.ID;
String name = List.name;
preparedStmt.setString(1, ID);
preparedStmt.setString(2, name);
preparedStmt.setString(3, List.password);

preparedStmt.setString(4, List.Usr_PassChgDays);
preparedStmt.setString(5, List.data_of_passChg);
preparedStmt.setString(6, List.User_type);

preparedStmt.executeUpdate();
//btnlogin.equals(result);
// panel.add(btnlogin);
// panel.add(jpfpass.getName(),btnlogin);
if (preparedStmt.equals(true)) {
JOptionPane.showMessageDialog(null, "Great sucess!!!");
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

} else {
JOptionPane.showMessageDialog(null, "FUCK!!!");
}

//JOptionPane.showMessageDialog(null, "User sucessfully created");
} catch (SQLException ex) {
Logger.getLogger(RychlikSystemversion0.class.getName()).log(Level.SEVERE, null, ex);
}
}

在互联网上到处寻找并尝试了所有技巧,老实说我很困惑。有人可以帮我吗?

最佳答案

请编辑 SQL 查询删除;结束查询

PreparedStatement preparedStmt = connection.prepareStatement("INSERT INTO `userlist`" + 
"VALUES( ?, ?, ?, ?, ?, ?)**;**");

关于Java sql 插入 JOptionpane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43579845/

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