Topic: 急询:如何将数组插入到数据库中 |
Print this page |
1.急询:如何将数组插入到数据库中 | Copy to clipboard |
Posted by: wewe8866 Posted on: 2006-11-04 21:36 请教各位高手。,因为我对数据库还不是太熟,有点玩不转, 运行一个网络应用程序,生成了一个有44个值的数组,想存入数据库中(mysql),不知如何存储,是建立一个表,做44列,一个值一个值存进去?觉得这个方法有点笨拙~ 还是有其他的直接把数组存入的方法,这个数组里的数值在以后的网页中还需要取出来调用的。不想再调用的时候麻烦~ |
2.Re:急询:如何将数组插入到数据库中 [Re: wewe8866] | Copy to clipboard |
Posted by: why Posted on: 2006-11-06 08:22 you could convert this 44 values into one string (with certain delimiter), and then you just need to save and retrieve one value from the database. |
3.Re:急询:如何将数组插入到数据库中 [Re: wewe8866] | Copy to clipboard |
Posted by: wewe8866 Posted on: 2006-11-06 09:59 楼上的方法好像不怎么能行的通啊 ,且不说怎么把它转为String,就是转了存了,再调用的时候如何转成原来的数组啊 ??? |
4.Re:急询:如何将数组插入到数据库中 [Re: wewe8866] | Copy to clipboard |
Posted by: why Posted on: 2006-11-07 18:43 wewe8866 wrote: Write your own simple String arrayToString(int[]) and int[] stringToArray(String) helper methods (assume you have an int array to store), e.g. StringBuffer sb = new StringBuffer(); String delimiter = "#"; for (int i = 1; i < intArray.length; i++) { sb.append(int).append(delimiter); } retrun sb.toString(); string[] strArray= str.split(delimiter); int[] intArray = new int[strArray.length]; for (int i = 1; i < strArray.length; i++) { intArray[i] = Integer.parseInt(strArray[i]); } return intArray; |
5.Re:急询:如何将数组插入到数据库中 [Re: why] | Copy to clipboard |
Posted by: alix1997 Posted on: 2006-11-07 23:29 表里需要插入数组的字段建成数组类型就可以啊。 |
6.Re:急询:如何将数组插入到数据库中 [Re: alix1997] | Copy to clipboard |
Posted by: why Posted on: 2006-11-08 19:23 alix1997 wrote: how? which database support this? which JDBC driver support this? Thanks. |
7.Re:急询:如何将数组插入到数据库中 [Re: why] | Copy to clipboard |
Posted by: wewe8866 Posted on: 2006-11-09 11:15 why wrote: 这方法不错,存进去了,不过长度有些长,我的串竟有840字节,还没进行读操作,我数据库用的text类型存储。 谢谢why~ |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |