200元手机费+200分求序列化例子 本人因项目急要,现在求java序列化例子,把一个数组,序列化到MYsql数据库,然后再取出来,能不能给定个例子,如果您的例子写得好,我可以用到,把手机号发过来,给你冲200元话费,本人说话算话。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这有何难~~~发份邮件到我邮箱[email protected] 是数组吗?你用Xstreamhttp://xstream.codehaus.org/序列化成xml...这样就成文本了,然后存放到数据库里面...多好啊..清楚..简单!序列化的class类要实现一个Serializable接口(详细看http://zhupan.javaeye.com/blog/26447)那么你的数组要封装到一个class类中,包装数组...呵呵! http://blog.csdn.net/ilibaba/archive/2009/03/10/3975680.aspx代码很多...呵呵 晚上给你写吧 不过在这之前你最好先说明你是用什么来完成 JDBC还是HIBERNATE 而且你要是提前搜索下 我保证你很后悔(偶不要手机费 给偶冲20QB偶就大满足了..) http://code.google.com/p/i18n-mead-properties-plugin/source/browse/trunk/source/src/meadproperty/util/XML2JavaUtil.java代码demoimport java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.OutputStreamWriter;import java.io.Writer;import meadproperty.service.Config;import com.thoughtworks.xstream.XStream;import com.thoughtworks.xstream.io.xml.DomDriver;public class XML2JavaUtil { public void java2XML(String xmlFile, Config cfg) throws Exception { XStream xs = new XStream(); File file = new File(xmlFile); FileOutputStream fs = new FileOutputStream(file.getAbsoluteFile()); Writer write = new OutputStreamWriter(fs); write.write("Hello, world\n"); xs.toXML(cfg, fs); System.out.println("ok3"+xmlFile); } public Config XML2Java(String xmlFile) throws FileNotFoundException { XStream reverse = new XStream(new DomDriver()); Config cfg = new Config(); FileInputStream fis = new FileInputStream(xmlFile); reverse.fromXML(fis, cfg); // fis.close(); System.out.println(cfg.toString()); return cfg; }} 下次我提问的时候标题我直接写回答正确者RMB2000 ,很有吸引力! 现在这年头都不爱写代码,给楼主提三个方案吧:1、按一对多方式映射:一方配置如下<array name="数组字段" cascade="all" fetch="join" > <key column="aid"/> <list-index column="id"/> <one-to-many class="多方类名"/> </array>这样会映射成数组长度数条记录2、自定义数据类型,参数Hibernate自定义数据型文档如果数组里是基本类型,就可以把数组转成一个带分隔符的串,再用自定义的类型系列化3、底层数据库用二进制类型,用纯J2EE层用Serializable机制。 对了,我要用hiberate,不要用 jdbc 开来都是充RMB来的,我不是,我是来看答案的 EL表达式 字符串相等判断 求大虾解决 再请大哥帮忙 myeclipse里DB Browser中sqlserver2000连接的一个问题 项目使用mysql数据库 链接中断的问题 webshpere配置oracle连接池的问题? 获取局域网内全部服务器当前时间 请教tomcat5的Filter问题,死活配置不了。 现在Resin都用什么版本,如何使用,我市菜鸟 关于iReport的使用 咨询下JAVA和C#在做BS数据库系统时的差别 关于struts标签的用法
http://xstream.codehaus.org/
序列化成xml...这样就成文本了,然后存放到数据库里面...
多好啊..清楚..简单!序列化的class类要实现一个Serializable接口(详细看http://zhupan.javaeye.com/blog/26447)
那么你的数组要封装到一个class类中,包装数组...呵呵!
代码很多...呵呵
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;import meadproperty.service.Config;import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;public class XML2JavaUtil {
public void java2XML(String xmlFile, Config cfg) throws Exception {
XStream xs = new XStream();
File file = new File(xmlFile);
FileOutputStream fs = new FileOutputStream(file.getAbsoluteFile());
Writer write = new OutputStreamWriter(fs);
write.write("Hello, world\n");
xs.toXML(cfg, fs);
System.out.println("ok3"+xmlFile);
} public Config XML2Java(String xmlFile) throws FileNotFoundException {
XStream reverse = new XStream(new DomDriver());
Config cfg = new Config();
FileInputStream fis = new FileInputStream(xmlFile);
reverse.fromXML(fis, cfg);
// fis.close();
System.out.println(cfg.toString());
return cfg;
}
}
1、按一对多方式映射:
一方配置如下
<array name="数组字段" cascade="all" fetch="join" >
<key column="aid"/>
<list-index column="id"/>
<one-to-many class="多方类名"/>
</array>
这样会映射成数组长度数条记录2、自定义数据类型,参数Hibernate自定义数据型文档
如果数组里是基本类型,就可以把数组转成一个带分隔符的串,再用自定义的类型系列化3、底层数据库用二进制类型,用纯J2EE层用Serializable机制。