導航:首頁 > 編程大全 > 一維數組插入資料庫

一維數組插入資料庫

發布時間:2023-08-03 14:05:35

1. 怎麼把 一維數組插入到資料庫

首先循環數組
for($i=0;$i<count(array);$i++){
循環後,這里就能取到每一個數組元素的字元串

$str=array[$i];

這個版str就是每一個數組元素的字元串了。權下面接著插入就可以了。

}

2. php如何寫入資料庫

數組吧,直接把數組轉字元串啊
implode() 函數返回由數組元素組合成的字元串。(適合一維數組)
$arr = array('Hello', 'World', 'I', 'love', 'Shanghai');
1 echo implode(" ",$arr);//加空格
the result : Hello World I love Shanghai
2 echo implode(",",$arr);//加逗號
the result : Hello,World,I,love,Shanghai

轉換數組為字元串後插入資料庫就可以了。

3. 如何把數組的值插入到資料庫 c#

1.設置一個資料庫的連接串,
string
connectStr
=
"User
Id=scott;Password=tiger;Data
Source=";
OracleConnection
conn
=
new
OracleConnection(connectStr);
OracleCommand
command
=
new
OracleCommand();
command.Connection
=
conn;
conn.Open();
2.通過循環寫入大量的數據
for
(int
i
=
0;
i
<
recc;
i++)
{
string
sql
=
"insert
into
dept
values("
+
i.ToString()
+
","
+
i.ToString()
+
","
+
i.ToString()
+
")";
command.CommandText
=
sql;
command.ExecuteNonQuery();
}
//設置一個資料庫的連接串
string
connectStr
=
"User
Id=scott;Password=tiger;Data
Source=";
OracleConnection
conn
=
new
OracleConnection(connectStr);
OracleCommand
command
=
new
OracleCommand();
command.Connection
=
conn;
//到此為止,還都是我們熟悉的代碼,下面就要開始嘍
//這個參數需要指定每次批插入的記錄數
command.ArrayBindCount
=
recc;
//在這個命令行中,用到了參數,參數我們很熟悉,但是這個參數在傳值的時候
//用到的是數組,而不是單個的值,這就是它獨特的地方
command.CommandText
=
"insert
into
dept
values(:deptno,
:deptname,
:loc)";
conn.Open();
//下面定義幾個數組,分別表示三個欄位,數組的長度由參數直接給出
int[]
deptNo
=
new
int[recc];
string[]
dname
=
new
string[recc];
string[]
loc
=
new
string[recc];
//
為了傳遞參數,不可避免的要使用參數,下面會連續定義三個
//
從名稱可以直接看出每個參數的含義,不在每個解釋了
OracleParameter
deptNoParam
=
new
OracleParameter("deptno",
OracleDbType.Int32);
deptNoParam.Direction
=
ParameterDirection.Input;
deptNoParam.Value
=
deptNo;
command.Parameters.Add(deptNoParam);
OracleParameter
deptNameParam
=
new
OracleParameter("deptname",
OracleDbType.Varchar2);
deptNameParam.Direction
=
ParameterDirection.Input;
deptNameParam.Value
=
dname;
command.Parameters.Add(deptNameParam);
OracleParameter
deptLocParam
=
new
OracleParameter("loc",
OracleDbType.Varchar2);
deptLocParam.Direction
=
ParameterDirection.Input;
deptLocParam.Value
=
loc;
command.Parameters.Add(deptLocParam);
//在下面的循環中,先把數組定義好,而不是像上面那樣直接生成SQL
for
(int
i
=
0;
i
<
recc;
i++)
{
deptNo[i]
=
i;
dname[i]
=
i.ToString();
loc[i]
=
i.ToString();
}
//這個調用將把參數數組傳進SQL,同時寫入資料庫
command.ExecuteNonQuery();

4. java如何把資料庫中的一列數值存入一維數組中

import java.sql.*;

public class OracleObject {
public static final String DBDRIVER =

"oracle.jdbc.driver.OracleDriver";
public static final String DBURL =

"jdbc:oracle:thin:@10.196.127.185:1521:notebook";
public static final String DBUSER = "scott";
public static final String DBPASS = "zjx123";
public static void main(String args[]) throws Exception {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "select ID from STUDENT"; //查詢學生學號

Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();

String[] arr=new String[10];
int i=0; //定義一個字元串數組
while(rs.next()) {
arr[i]=rs.getString(1);
i++; //把學生序號賦值給數組
}
for(j=0;j<arr.length;j++){
System.out.println(arr[j])
} //列印數組

rs.close();
pstmt.close();
conn.close();
}
}

閱讀全文

與一維數組插入資料庫相關的資料

熱點內容
如何設置胎壓監測數據 瀏覽:530
降噪工具 瀏覽:692
obs編程是什麼意思 瀏覽:859
怎麼看c4d打開了多少個文件 瀏覽:792
蘋果銀河高清壁紙 瀏覽:811
怎麼從蘋果電腦垃圾桶找迴文件 瀏覽:771
介面文件不能用action寫嗎 瀏覽:85
svn代碼提交規范 瀏覽:642
在宣讀多少號文件時怎麼讀數字 瀏覽:921
網站中的區域網訪問量是什麼意思 瀏覽:397
蘋果啟動助理識別不到鏡像文件 瀏覽:670
為什麼每次文件都問是否改變應用 瀏覽:232
pinterestapp怎麼進去 瀏覽:968
json實現通用的下拉框 瀏覽:524
hc在編程中是什麼意思 瀏覽:482
javamd文件怎麼打開方式 瀏覽:90
python載入mat文件格式 瀏覽:615
sw編程是什麼 瀏覽:881
網路眾籌有哪些特點 瀏覽:896
有哪些不需要會員的看動漫的app 瀏覽:533

友情鏈接