pstat= con.prepareStatement("INSERT INTO pointer_act VALUES (?,?)");
String xmlfile="C:/IBM/oriXML/1.xml";
// String xmlString = "";//从文件中读取XML数据,构造成String类型的数据try{
// InputStreamReader isr = new InputStreamReader(new FileInputStream(xmlfile), "UTF-8");
// BufferedReader in = new BufferedReader(isr);
// String line =null;
// while((line = in.readLine()) !=null)
// {
// xmlString += line;
// }
// in.close();
注:标颜色的是把文件流读取后转化为String然后存入,这是最慢的方法。但是如果要在存储的时候修改XML的内容就只能用这种方法了。
pstat.setString(1, "4");
File file = new File(xmlfile);
pstat.setBinaryStream(2, new FileInputStream(file), (int)file.length());
这种是比较快的方法,缺点在于不能修改XML的内容了。
pstat.executeUpdate();