且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用JAVA插入phpmyadmin数据库

更新时间:2023-02-07 09:07:03

首先清除该区域 - 那里是不是这样的'phpmyadmin'数据库... phpmyadmin是管理不同类型的数据库的前端...

首先 - 看你使用什么数据库,并根据你的代码示例它是一种SQL风格,可能是MySQL或变体(MariaDB)...

下一步是搜索'Java','MySQL'和'INSERT'的组合...

此示例s如何在准备好的SQL语句中从局部变量中注入值:

Java MySQL INSERT示例(使用PreparedStatement)| alvinalexander.com [ ^ ]


 字符串 sql1 =   INSERT INTO kunden(name,nachname)VALUES(' txtfldVorname.getText() '); 



首先,你需要学习Java。搜索Jaba字符串连接。



其次,不是你问题的解决方案,而是你遇到的另一个问题。

永远不要构建SQL查询通过连接字符串。迟早,您将使用用户输入来执行此操作,这会打开一个名为SQL注入的漏洞,这对您的数据库很容易并且容易出错。

名称中的单引号你的程序崩溃。如果用户输入像Brian O'Conner这样的名称可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞,崩溃是最少的问题,恶意用户输入,并且它被提升为具有所有凭据的SQL命令。

SQL注入 - *** [ ^ ]

SQL注入 [ ^ ]

按示例进行SQL注入攻击 [ ^ ]

PHP:SQL注入 - 手册 [ ^ ]

SQL注入预防备忘单 - OWASP [ ^ ]


Hi guys

how can I solve this

String sql1 = "INSERT INTO kunden (name,nachname) VALUES('"txtfldVorname.getText()"')";



I am trying to take the string which I entered in the textfield, I am so confused noting works.

Thank you all.

What I have tried:

<pre>String sql1 = "INSERT INTO kunden (name,nachname) VALUES('"txtfldVorname.getText()"')";

First of all clear the area - there is no such a thing 'phpmyadmin' database... phpmyadmin is a front-end to manage databases of different kind...
So first - see what database do you use, and based on your code sample it is a SQL flavor, probably MySQL or variant (MariaDB)...
The next step is to search for the combination of 'Java', 'MySQL' and 'INSERT'...
This sample shows how to inject values from local variables in a prepared SQL statement:
A Java MySQL INSERT example (using PreparedStatement) | alvinalexander.com[^]


String sql1 = "INSERT INTO kunden (name,nachname) VALUES('"txtfldVorname.getText()"')";


First of all, you need to learn Java. Search for Jaba string concatenation.

secondly, not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]