Click here to Skip to main content
15,896,526 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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()"')";
Posted
Updated 6-May-18 10:12am

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[^]
 
Share this answer
 
Comments
Member 13814158 6-May-18 14:39pm    
Thank you so much for your answer.

I'm so sorry for my stupid questions. I am new in this area ..
what do you mean with front end ???
Kornfeld Eliyahu Peter 6-May-18 14:48pm    
Front-end is something the users see... An UI to handle some task...
Java
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900