0
Я хранил xml в базе данных Java. В java xml извлекается успешно, но в моем sql я не могу его каким-то образом сохранить. Данные не были вставлены в mysql.Как хранить несколько XML-данных в базе данных Java
public static void main (String argv []) throws SQLException{
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new File("C:/Users/GbsIndia1/Desktop/appsettings.xml"));
// normalize text representation
doc.getDocumentElement().normalize();
System.out.println ("Root element of the doc is " +
doc.getDocumentElement().getNodeName());
NodeList listOfPersons = doc.getElementsByTagName("Name");
int totalPersons = listOfPersons.getLength();
System.out.println("Total no of Device : " + totalPersons);
for(int s=0; s<listOfPersons.getLength() ; s++){
Node firstPersonNode = listOfPersons.item(s);
if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){
Element firstPersonElement = (Element)firstPersonNode;
//-------
NodeList firstNameList = doc.getElementsByTagName("Name");
Element firstNameElement = (Element)firstNameList.item(s);
NodeList textFNList = firstNameElement.getChildNodes();
System.out.println("Hardware Name is " +
((Node)textFNList.item(0)).getNodeValue().trim());
}
}
Class.forName("com.mysql.jdbc.Driver");
}catch (SAXParseException err) {
System.out.println ("** Parsing error" + ", line "
+ err.getLineNumber() + ", uri " + err.getSystemId());
System.out.println(" " + err.getMessage());
}catch (SAXException e) {
Exception x = e.getException();
((x == null) ? e : x).printStackTrace();
}catch (Throwable t) {
t.printStackTrace();
}
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test1" ,"root","");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into test1(name) values('"+Name+"')");
В имени XML-тега Есть несколько значение как
<Category>
<Name>ABC</Name>
<Name>DEF</Name>
<Name>GHI</Name>
</Category>
Я хочу, чтобы хранить эти данные в MySQL. Так в чем проблема с моим кодом?
Что IST '' name' в Int я = st.executeUpdate ("вставить test1 имя) значения ((» "+ имя +" ') ");'? – drkunibar