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

一維數組插入資料庫

發布時間: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();
}
}

閱讀全文

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

熱點內容
列印機怎麼通過網路連接 瀏覽:880
java用來分配內存的運算符 瀏覽:533
ps液化平滑工具 瀏覽:69
投標文件由哪個單位留存 瀏覽:162
java通過經緯度或取城市名 瀏覽:984
蘋果6手機文件在哪裡找到 瀏覽:298
windows系統哪個文件是桌面 瀏覽:342
qq代理國際版295破解 瀏覽:81
linux怎麼抓取臨時文件 瀏覽:702
在手機上怎麼將圖片弄成文件 瀏覽:974
蘋果賬戶名字怎麼修改 瀏覽:423
奢侈品哪個網站 瀏覽:624
數據有限公司經營范圍有哪些 瀏覽:37
網路媒介主要有哪些渠道 瀏覽:751
編程後處理後怎麼輸入到機床里 瀏覽:607
手機輸入壓縮文件密碼忘了怎麼辦 瀏覽:258
u8怎麼查生產訂單未領料數據 瀏覽:973
編程貓從哪裡來 瀏覽:577
怎麼編程測數控車間隙 瀏覽:721
文件口罩有哪些圖案 瀏覽:192

友情鏈接