以文本方式查看主题

-  W3CHINA.ORG讨论区 - 语义网·描述逻辑·本体·RDF·OWL  (http://bbs.xml.org.cn/index.asp)
--  『 WORD to XML, HTML to XML 』  (http://bbs.xml.org.cn/list.asp?boardid=13)
----  如何将XML数据导入数据库  (http://bbs.xml.org.cn/dispbbs.asp?boardid=13&rootid=&id=17204)


--  作者:peipei
--  发布时间:4/20/2005 4:44:00 AM

--  如何将XML数据导入数据库
各位高手,能否教我如何将XML数据导入数据库啊,我在做毕业设计,急死我了
--  作者:cxh0926
--  发布时间:5/5/2005 10:22:00 PM

--  
顶起。希望高手来解决下,我也正要问的!
--  作者:CB1058
--  发布时间:5/6/2005 7:05:00 PM

--  
so do I...
--  作者:linyan
--  发布时间:5/20/2005 3:14:00 PM

--  
我也是别人教的,是做毕业设计用的,或许可以看看用得着
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class connnect1 {
 String driverName = "com.mysql.jdbc.Driver";
 String databaseUrl = "jdbc:mysql://localhost:3306/ly";
 String user = "java";
 String password = "java";
 static Statement stat =null;
 static Connection con = null;
 
 public void conn(){
  
  try {
   Class.forName(driverName);
   System.out.println("成功加载Mysql数据库驱动!");
  } catch (ClassNotFoundException e) {
   System.out.println("加载Mysql数据库驱动失败!");
   System.out.println(e.getMessage());
   return;
  }
  try {
   con = DriverManager.getConnection(databaseUrl, user,
     password);
   System.out.println("数据库连接成功!");
  stat = con.createStatement();
   
//   System.out.println(otherversions);
  
   
  } catch (SQLException e) {
   System.out.println("数据库连接失败!");
   System.err.println("SQLExecption: " + e.getMessage());
   return;
  }
 }
public void ineart_Data(String virusname, String otherversions,
  String alias, String details) throws SQLException {
 String insertData = ("INSERT INTO kav(virusname,otherversions,alias,Details)"
   + "VALUES('"
   + virusname
   + "','"
   + otherversions
   + "','"
   + alias + "','" + details + "')");
 stat.executeQuery(insertData);

}
public void close() throws SQLException{
 stat.close();
 con.close();
}
}


--  作者:11924ef
--  发布时间:5/21/2005 11:27:00 AM

--  
以下是引用linyan在2005-5-20 15:14:03的发言:
我也是别人教的,是做毕业设计用的,或许可以看看用得着
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class connnect1 {
  String driverName = "com.mysql.jdbc.Driver";
  String databaseUrl = "jdbc:mysql://localhost:3306/ly";
  String user = "java";
  String password = "java";
  static Statement stat =null;
  static Connection con = null;
  
  public void conn(){
   
   try {
    Class.forName(driverName);
    System.out.println("成功加载Mysql数据库驱动!");
   } catch (ClassNotFoundException e) {
    System.out.println("加载Mysql数据库驱动失败!");
    System.out.println(e.getMessage());
    return;
   }
   try {
    con = DriverManager.getConnection(databaseUrl, user,
      password);
    System.out.println("数据库连接成功!");
   stat = con.createStatement();
    
//   System.out.println(otherversions);
   
    
   } catch (SQLException e) {
    System.out.println("数据库连接失败!");
    System.err.println("SQLExecption: " + e.getMessage());
    return;
   }
  }
public void ineart_Data(String virusname, String otherversions,
   String alias, String details) throws SQLException {
  String insertData = ("INSERT INTO kav(virusname,otherversions,alias,Details)"
    + "VALUES('"
    + virusname
    + "','"
    + otherversions
    + "','"
    + alias + "','" + details + "')");
  stat.executeQuery(insertData);

}
public void close() throws SQLException{
  stat.close();
  con.close();
}
}



是在什么地方引用这段话呢?在xml中?
--  作者:wangqiwu4585
--  发布时间:6/3/2005 11:37:00 AM

--  
不知道有没有vb做的,请赐教啊!!
--  作者:kiy6585
--  发布时间:6/13/2005 11:52:00 PM

--  
对啊!怎么都不用vb.net做的呢?
--  作者:jx27
--  发布时间:6/17/2005 7:56:00 AM

--  
以下是我的用XSLT把XML的数据输入数据库(MY SQL)的例子:

<xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  <xsl:output method = "text" indent = "yes"/>
  <xsl:template match = "/" >
  <xsl:apply-templates select="*"/>
  </xsl:template>
  <!-- get the value to insert into the table "Qnre" -->
  <xsl:template match = "Qnre">
    <xsl:text>insert into Qnre values ('</xsl:text>
    <xsl:value-of select="@id"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="@client"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="@author"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="@contact"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="@version"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="@topic"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="@date"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qtitle"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qtitle/@clientlogo"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qintro/@privacy"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qintro/@heading"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qintro/@para"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qintro/@Qitem"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qbody/@action"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qbody/@uploads"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qbody/@bid"/>
    <xsl:text>');
</xsl:text>
    <!-- set to <Qsection> -->
    <xsl:apply-templates select="Qbody/Qsection"/>
  </xsl:template>
  <!-- get the value to insert into the table "Qsection" -->
  <xsl:template match = "Qsection">
   <xsl:text>insert into Qsection values ('</xsl:text>
   <xsl:value-of select="/Qnre/@id"/>
   <xsl:text>','</xsl:text>
   <xsl:value-of select="@sid"/>
   <xsl:text>','</xsl:text>
   <xsl:value-of select="Qintro/Qprivacy"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qintro/Qheading"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qintro/Qpara"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qintro/Qitem"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="goto"/>
    <xsl:text>');
</xsl:text>
    <!-- set to <Question> -->
    <xsl:apply-templates select="Question"/>
  </xsl:template>
  <!-- get the value to insert into the table "Question" -->
  <xsl:template match="Question">
    <xsl:text>insert into Question values ('</xsl:text>
    <xsl:value-of select="/Qnre/@id"/>
    <xsl:text>','</xsl:text>
    <!-- set to <Qsection> -->
    <xsl:value-of select="../@sid"/>
    <xsl:text>','</xsl:text>
   <xsl:value-of select="@qid"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="@kind"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qintro/Qprivacy"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qintro/Qheading"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qintro/Qpara"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qintro/Qitem"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qtext"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qanswer/Qother"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qanswer/@answertype"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Qanswer/Qlink/@goto"/>
    <xsl:text>');
</xsl:text>
    <!-- set to <Qchoice> -->
    <xsl:apply-templates select="Qanswer/Qchoice"/>
  </xsl:template>
  <!-- get the value to insert into the table "Qchoice" -->
  <xsl:template match="Qchoice">
    <xsl:text>insert into Qchoice values ('</xsl:text>
    <xsl:value-of select="/Qnre/@id"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="/Qnre/Qbody/Qsection/@sid"/>
    <xsl:text>','</xsl:text>
    <!-- set to <Question> -->
    <xsl:value-of select="../../@qid"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="@val"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="/Qother/Qlink/@goto"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>');
</xsl:text>
    </xsl:template>
</xsl:stylesheet>

/===========
输出结果文件可以另存为SQL FILE。然后在LINUX的COMMEND LINE里直接输入文件名就能
自动INSERT INTO DATABASE了。


--  作者:amyflower
--  发布时间:6/17/2005 10:58:00 AM

--  
可以用一用JBuilderX
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
78.125ms