How to write java sql statement
About the splicing rules of SQL statements in Java
The implementation target statement is the following. Note that the java variable here is idd
int idd; String sql = "SELECT id, piUrl FROM picinfos WHERE id BETWEEN '" + idd + "' AND 10" ;
The string in java can only be double quoted. If a variable needs to be spliced in the string, the variable must be single quoted. Surround it, then add two double quotes and then two plus signs, and the variable is in the middle.
Splicing steps
1. Write the specific SQL statement (no variables have specific values), such as the above sql
//查询picinfos表中id为2到10的id和piUrl值 String sql = "SELECT id, piUrl FROM picinfos WHERE id BETWEEN 2 AND 10" ;
2. At this time, if you want to change 2 to id (int type variable), you only need to modify it in the middle. First, delete 2 and replace
String sql = "SELECT id, piUrl FROM picinfos WHERE id BETWEEN ' ' AND 10" ;
3 with single quote ' '. Then add double quotes between the single quotes " "
String sql = "SELECT id, piUrl FROM picinfos WHERE id BETWEEN ' " " ' AND 10" ;
4. Then add a plus sign between the double quotes
String sql = "SELECT id, piUrl FROM picinfos WHERE id BETWEEN ' " + + " ' AND 10" ;
5. Finally, add the variable idd between the plus sign and finish
String sql = "SELECT id, piUrl FROM picinfos WHERE id BETWEEN ' " + idd + " ' AND 10" ;
Function: Start with the SQL prototype, replace it with single quotes, add double quotes in the middle, add double plus signs in the middle, and add variables in the middle.
So how is the Java string converted into a SQL statement?
As shown in the picture
php Chinese Internet, a large number of free Java introductory tutorials, welcome to learn online!
The above is the detailed content of How to write java sql statement. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools