Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » MySQL  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 急询:如何将数组插入到数据库中
wewe8866





发贴: 17
积分: 0
于 2006-11-04 21:36 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
请教各位高手。,因为我对数据库还不是太熟,有点玩不转,
运行一个网络应用程序,生成了一个有44个值的数组,想存入数据库中(mysql),不知如何存储,是建立一个表,做44列,一个值一个值存进去?觉得这个方法有点笨拙~
还是有其他的直接把数组存入的方法,这个数组里的数值在以后的网页中还需要取出来调用的。不想再调用的时候麻烦~



失败是成功之母,逃避失败,也就拒绝了成功~!
作者 Re:急询:如何将数组插入到数据库中 [Re:wewe8866]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-11-06 08:22 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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.


作者 Re:急询:如何将数组插入到数据库中 [Re:wewe8866]
wewe8866





发贴: 17
积分: 0
于 2006-11-06 09:59 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
楼上的方法好像不怎么能行的通啊 ,且不说怎么把它转为String,就是转了存了,再调用的时候如何转成原来的数组啊 ???


失败是成功之母,逃避失败,也就拒绝了成功~!
作者 Re:急询:如何将数组插入到数据库中 [Re:wewe8866]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-11-07 18:43 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
wewe8866 wrote:
楼上的方法好像不怎么能行的通啊 ,且不说怎么把它转为String,就是转了存了,再调用的时候如何转成原来的数组啊 ???

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;


why edited on 2006-11-07 18:45

作者 Re:急询:如何将数组插入到数据库中 [Re:why]
alix1997





发贴: 7
积分: 0
于 2006-11-07 23:29 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
表里需要插入数组的字段建成数组类型就可以啊。


作者 Re:急询:如何将数组插入到数据库中 [Re:alix1997]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-11-08 19:23 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
alix1997 wrote:
表里需要插入数组的字段建成数组类型就可以啊。

how?
which database support this?
which JDBC driver support this?

Thanks.



作者 Re:急询:如何将数组插入到数据库中 [Re:why]
wewe8866





发贴: 17
积分: 0
于 2006-11-09 11:15 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
why 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;


这方法不错,存进去了,不过长度有些长,我的串竟有840字节,还没进行读操作,我数据库用的text类型存储。
谢谢why~


wewe8866 edited on 2006-11-09 18:40

失败是成功之母,逃避失败,也就拒绝了成功~!

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2020 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号
客服电话 0592-8750026    客服信箱 714923@qq.com    客服QQ 714923