How to use arrays to input data into SQL
Construct a large SQL statement, Insert into wer(A1,A2...A1000) Values(@a1,@a2,...@a1000). There are 1000 parameters in it. Just assign values to the parameter array in a loop and then execute it.
You can use a loop to generate this string
string Sql,param;
Sql="";param="";
for(int i=1;i{
Sql ="A" i.ToString() ",";
param ="@a" i.ToString() ",";
}
Sql="Insert into wer("Sql.Substring(0,Sql.Length-1) ") Values ("param.Substring(0,param.Length-1));
Assign a value to the parameter array of this Sql, and then execute this SQL;
But I remember that under 2000, the maximum length of a single SQL command was 4K bytes (I don’t remember clearly, you can try it yourself). If there are 1000 fields, just writing the field names will exceed 4K bytes.
If the SQL statement is too common, it needs to be split into two, one inserts and returns an id, and then updates based on the second one, or you can bring an id yourself in the parameters.
How to use arrays to store data in Oracle
declare
--Define the IntArray type, which is an array in which each element is of type int
Type IntArray is table of int;
--Define a variable of type IntArray
v_array IntArray := IntArray();
begin
--Storing data into the array
for i in 1.. 100 loop
--Need to expand array
v_array.extend;
v_array(i) := i;
end loop;
--Output the contents of the array
for i in 1.. 100 loop
dbms_output.put_line(v_array(i));
end loop;
end;
SQL>set serverout on;
SQL>declare
2 --Define the IntArray type, which is an array in which each element is of type int
3 Type IntArray is table of int;
4 --Define a variable of type IntArray
5 v_array IntArray := IntArray();
6 begin
7 --Storing data into the array
8 for i in 1.. 100 loop
9 --Need to expand array
10 v_array.extend;
11 v_array(i) := i;
12 end loop;
13
14 --Output the contents of the array
15 for i in 1.. 100 loop
16 dbms_output.put_line(v_array(i));
17 end loop;
18 end;
19 /
1
2
3
4
5
6
7
8
9
10
Omit 90 lines here
PL/SQL procedure successfully completed
SQL>
How does the java program store a string array into the database
public class ddd {
public static void main(String args[]){
String driverClass="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/find";//find database name
String user="root";//
String password="root";//MYSQL
Connection conn;
try {
Class.forName(driverClass).newInstance(); conn=DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
int i=0;
String a[]={"sad","dsds","dsfss"};
String sql="insert into XX values (null,'" a[i] "')";
for(i=0;i
int rs=stmt.executeUpdate(sql);
}catch(Exception ex){
ex.printStackTrace();
}
}
Create a table with two columns, ID and word; ID is set to increase automatically;
If you have any questions, please contact me.
The above is the detailed content of How to enter data into SQL database using arrays. For more information, please follow other related articles on the PHP Chinese website!

If you want to use ChatGPT via VPN in an unsupported country, region, or territory, do you know which is the best VPN for ChatGPT? In this post, php.cn Software will introduce some good choices for you. You can select one according to your requiremen

How to fix the “XboxPcAppFT.exe bad image” issue on Windows 11/10? This post from php.cn presents multiple methods to resolve the annoying issue. Please go on with your reading.

What should do when you want to delete a file or folder in OneDrive, but find that OneDrive files or folders cannot be deleted? Now you can read this post from php.cn to get the best solutions to fix the “OneDrive files cannot be deleted in Windows 1

The error message “display connection might be limited” is an annoying issue when you start the device. In this post from php.cn, you can get detailed information about what causes this problem and how to resolve it quickly.

Microsoft releases a new build to Insiders in the Dev Channel and it is Windows 11 build 25115. This is a higher build compared to the build released to the Beta Channel. You can follow this php.cn post to learn some related information about it.

How do I free up space on my C drive or how do I clear waste on my C drive? This is the topic that php.cn focuses on here. If your C drive is full of old apps and unnecessary programs, you can choose to clean up it. Let’s get started.

ChatGPT has been updated with GPT-4. To help you better understand this update, we will introduce the differences between ChatGPT 4 and ChatGPT 3. In addition, if you want to recover deleted files on Windows, you can try php.cn Power Data Recovery.

How can you download and install Media Feature Pack if you are using Windows 11 N or KN editions? In this post, php.cn offers a step-by-step guide on getting Windows 11 Media Feature Pack. Let’s look through some details.


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

Atom editor mac version download
The most popular open source editor

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment
