Java jdbc mysql updatequery [英] Java jdbc mysql updatequery
本文介绍了Java jdbc mysql updatequery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好!我试着写一些方法,这将在日期基础上添加一条新记录。
代码:
Hello! Im trying to write some method, which will add a new record to date base.
Code:
public void insertToPlayList() {
try {
connecting();
stat6 = Connection.createStatement();
stat6.executeUpdate("INSERT INTO odtwarzane VALUES('','2','4','2','2015-10-10','10:10')");
connecting();
} catch (SQLException Exception) {
JOptionPane.showMessageDialog(null, "Wystąpił problem z dodaniem rekordu.", "Błąd", JOptionPane.ERROR_MESSAGE);
}
}
最初,这种方法获得了5个参数,但是为了解决问题,我将其删除了。
Originally, this method is getting 5 paramenters, but for fixing problem i removed it.
public void insertToPlayList(int filmId, int cinemaId, int priceId, String date, String time) {
try {
connecting();
stat6 = Connection.createStatement();
String str = ("INSERT INTO odtwarzane (id_of, id_filmu, id_kina, id_ceny, data, godzina) VALUES (," + filmId + ", " + cinemaId + ", " + priceId + ", '" + date + "', '" + time + "');");
stat6.executeUpdate(str);
connecting();
} catch (SQLException Exception) {
JOptionPane.showMessageDialog(null, "Wystąpił problem z dodaniem rekordu.", "Błąd", JOptionPane.ERROR_MESSAGE);
}
}
我在PhpMyAdmin上查看了,并且工作表已经完成
I checked on PhpMyAdmin, and statment was worked
INSERT INTO odtwarzane VALUES('','2','4','2','2015-10-10','10:10');
无论如何,程序抛出SQLException,我不知道如何解决它。
我尝试了什么:
我试图以多种方式更改语句或代码,我当时在互联网上寻找一些解决方案,但我没有找到它。
Anyway, program is throwing SQLException, and i dont know how to fix it.
What I have tried:
I tried to change statement or code in many ways, and i was looking for some solution in the Internet, but i didnt find it.
推荐答案
您在Statement子句的语句中有错误:请参阅 PHP将数据插入MySQL [ ^ ] for正确的语法。此外,您不应对SQL语句使用字符串连接:请参阅 bobby-tables.com:防止SQL注入的指南 [< a href =http://bobby-tables.com/about.htmltarget =_ blanktitle =New Window> ^ ]。
You have an error in your statement for the Values clause: see PHP Insert Data Into MySQL[^] for correct syntax. Also you should not use string concatenation for SQL statements: see bobby-tables.com: A guide to preventing SQL injection[^].
这篇关于Java jdbc mysql updatequery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文