import javasqlConnection;
import javasqlDriverManager;
import javasqlPreparedStatement;
import javasqlResultSet;
import javasqlSQLException;
import javautilLinkedList;
import javautilList;
public class DataToArray {
public static void main(String[] args) throws Exception {
String url = "jdbc:mysql://localhost:3306/test";// 改成你的数据库连接
Connection conn = DriverManagergetConnection(url, "root", "fuhaiwei");// 改成你用户名密码
String sql = "select from user";// 改成你的查询语句
PreparedStatement prestmt = connprepareStatement(sql);
ResultSet rs = prestmtexecuteQuery();
Object[][] data = getDataArray(rs);
printArray(data);
rsclose();
prestmtclose();
connclose();
}
private static void printArray(Object[][] data) {
for (int i = 0; i < datalength; i++) {
for (int j = 0; j < data[i]length; j++) {
Systemoutprint(data[i][j] + " ");
}
Systemoutprintln();
}
}
private static Object[][] getDataArray(ResultSet rs) throws SQLException {
List<Object[]> list = new LinkedList();
while (rsnext()) {
// 改成你的列名
Object[] objects = new Object[] { rsgetInt("id"), rsgetString("username"),
rsgetString("password") };
listadd(objects);
}
return listtoArray(new Object[0][0]);
}
}
输出效果:
针对你的问题,我写出ASP的代码如下:
<%
dburl="dbmdb"
Set conn = ServerCreateObject("ADODBConnection")
connstr="Provider=MicrosoftJetOLEDB40;Data Source=" & ServerMapPath(dburl)
'connstr="driver={Microsoft Access Driver (mdb)};dbq=" & ServerMapPath(""&dburl&"")
connOpen connstr
action=request("action")
info=replace(replace(trim(requestForm("info")),CHR(10),","),chr(13),"")
if action="up" then
rowd=split(info,",")
for i = Lbound(rowd) to ubound(rowd)
'nowselectid=trim(rowd(i))
set rs=servercreateobject("adodbrecordset")
sql="select from aaa"
rsopen sql,conn,3,3
rsaddnew
k=1
myStr=split(rowd(i),"|")
for j = Lbound(myStr) to ubound(myStr)
rs("biao"&k)=myStr(j)
k=k+1
next
rsupdate
rsclose
set rs=nothing
next
responsewrite "写入完成!"
end if
%>
以上代码经测试,100%能达到你的要求!
以上就是关于java中如何将数据库中多个字段的值存入二维数组的一个元素中全部的内容,包括:java中如何将数据库中多个字段的值存入二维数组的一个元素中、asp切割字符串,把生成的数据存入二维数组(数据库)、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)