- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 NetBeans-8.0.2 和 JavaFX (FXMLApplication) 制作一个待办事项列表,将内存存储到 MySQL 数据库中。
我知道,SQL 查询需要引号 -> ( ' ) 和双引号 -> ( ") 与理解字符串相同。
现在,我正在尝试的是,(今天是我姐姐的生日)我正在尝试在我的列表中添加一个任务,上面写着:这是 Rahi 的生日!
但是,由于sql查询,它失败了。
这是因为在代码内部,输入的引号使整个 sql 查询变得复杂。
@FXML
private void handleAddTaskAction(ActionEvent event) {
String date = addTaskDatePicker.getValue().toString();
System.out.println(date);
String hour = hourComboBox.getValue() + "";
String minute = minuteComboBox.getValue() + "";
String where = whereField.getText();
String header = headerField.getText();
String description = descriptionArea.getText();
if(hour.length()==0)
hour= "12 AM";
if(minute.length()==0)
minute= "00";
if(header.length()==0)
header= "(No header available)";
if(description.length()==0)
description= "(No description available)";
if(header.length()==0 && description.length()==0){
header= "(Empty task)";
description= "(Empty description)";
}
String query = "insert into task values('" + date + "','" + hour + " " + minute + " minutes', '"
+ header + "', '" + description + "', 'at " + where + "');";
if (date.length() >= 1) {
try {
statement.execute(query);
} catch (SQLException ex) {
//Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setHeaderText("Error occured!");
alert.showAndWait();
}
} else {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setHeaderText("You must select a date.");
alert.showAndWait();
}
}
我想在键入消息时存储该消息。有什么解决办法吗?
我的数据库表描述和 GUI 附为图片。问我是否还需要什么。谢谢。
图片:GUI和图片:Table description
最佳答案
只需使用 PreparedStatement注入(inject)你的值(value)观,它会为你转义它们。
关于java - MySQL:插入查询中出现引号 -> ( ' ) and double quotation -> ( ") 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34071683/
我正在将几个基于 OCaml 的模块转换为 F#,并运行到 OCaml ''Quotation.add'' 编译器指令以获取引号扩展器。 A quotation expander is a funct
我有以下返回公共(public) IP 的代码 def gather_public_ip(): ACCESS_KEY = config.get('aws','access_key')
文件test.ml仅包含一行: let foo = > 然后我使用以下命令行将camlp4应用于该文件: camlp4o pa_extend.cmo test.ml 输出是: File "test.m
这是我试图解决的问题的简化版本。所以,尽量不要破解答案:) 在 R 中,默认情况下 '"' == '\"' 因此,当我使用 URLencode('\"') URLencode('"') 我得到了相同的
我是 SqlAlchemy 和 Firebird DB 的新手。 我可以使用 DBeaver 直接创建表: CREATE TABLE NEWTABLE ( COLUMN1 FLOAT,
我有以下代码: curl -X GET http://localhost:9200/INDEXED REPOSITORY/_search -d '{"query": {"constant_score"
给定一个 F# 记录: type R = { X : string ; Y : string } 和两个对象: let a = { X = null ; Y = "##" } let b = {
在 docker-compose ( https://docs.docker.com/compose/compose-file/#restart ) 的 docker 文档中给出了此重新启动选项: r
我正在使用SBJson通过JSON字符串进行解析。一些请求返回如下内容: { "jsonResponse":[{ "id":"2", "name":"Somename", "title":"Js
我有一份包含许多引号的文件。我需要用 \quotation{ (开始)和 } (结束)替换所有对 " ,以便在 ConTeXt 中使用,例如: "Do not be afraid," said the
下面的代码取 self 正在开发的一个更大的项目。 本节的目的是将输出格式化为列表,任何地方都不带引号。 但是,当我尝试将输出格式化为列表时,它的外面有引号,我浏览了多个论坛,但找不到任何遇到确切问题
我正在为一个学校项目制作一个基于 Faroo.com ( http://www.faroo.com/hp/api/api.html ) API 的搜索引擎。我想索引 Faroo 的索引,以便用户(在我
我正在使用 ProcessBuilder 运行 FFMPEG 来转换和标记我的一些 MP3 文件。 在 .bat 文件中手动使用以下内容按预期工作: "E:\Dokumente\workspace\M
我想使用以下功能: =COUNTIF(B3:B400;"<=24/02/2012") 其中 24/02/2012 应替换为指向特定单元格的指针。当我向下扩展这个函数时,指针应该也会增加。 我怎样才能做
我在使用 SQLAlchemy 进行 postgresql 查询时遇到问题。 我使用这行代码创建了一些大表: frame.to_sql('Table1', con=engine, method='mu
我正在处理一个包含大量信息的 Excel 工作表。有些列包含我需要在脚本中使用的信息,我使用以下代码来保存我在单击按钮后在 .txt 文件中选择的内容。 Private Sub CommandButt
我有一个 json 格式的对象数组: [ { "name": "obj1", "list": [ "elem1",
如果我开始自行输入文件路径,然后按 Tab 完成它,它会很好地工作,即 In [1]: ~ [TAB] In [1]: /Users/zhermes/ 但如果它在报价内,它也会自动关闭报价,即 In
所以我尝试使用 Python 读取 Arduino 板上 DS18B20 温度传感器的值。在我的Python代码中,我使用Pyserial来访问端口,下面是代码。 import serial def
这个问题已经有答案了: How does a PreparedStatement avoid or prevent SQL injection? (10 个回答) 已关闭 7 年前。 我正在尝试使用
我是一名优秀的程序员,十分优秀!