100分求SAX解析XML导入数据库代码,牛人乱入
如题,我的XML文档如下,要将下列字段得到然后导入数据库,我现在自己做主要是时间那个字符串老是取不全,我的代码也附在这里吧,如果代码可用,我再送他100分
<DATA>
<TABLE tableName= "user02 ">
<USERID> 1000000001 </USERID>
<CREATEDATE> 2007-02-11 00:00:00.0 </CREATEDATE>
<CRTBY> 012011 </CRTBY>
<MODIFYDATE> null </MODIFYDATE>
<LSTMODBY> null </LSTMODBY>
<CMT> 0 </CMT>
<CMTUSER> null </CMTUSER>
<CMTDATE> null </CMTDATE>
<APPSTATUS> 0 </APPSTATUS>
<REMARK> 921176 </REMARK>
<ISNEW> 1 </ISNEW>
<LASTUPDATE> 2007-04-28 10:58:00.0 </LASTUPDATE>
</TABLE>
</DATA>
我的代码,其中dbcon是个封装了数据库访问的类,大家不要管它
public class SAXReader extends DefaultHandler{
dbcon connect = new dbcon();
String columnValue = null;
String tableName = null;
String columnName = null;
String sql = "insert into " ;
public void startDocument() throws
SAXException {
}
public void processingInstruction(String taget, String data) throws SAXException {
}
public void startElement(String uri, String localName, String qName, Attributes attr) throws SAXException {
if( "TABLE ".equals(qName))
{
for(int i = 0;i <attr.getLength();i++)
{
tableName = attr.getValue(i);
}
sql += tableName + " values( ";
}
else
{
columnName = qName;
}
}
public void characters(char[] ch, int start, int length) throws SAXException {
columnValue=new String(ch,start,length).toString().trim();
if( " ".equals(columnValue))
{
columnValue = " ' ' ";
}
else
{
if(! "null ".equals(columnValue)&&! "NULL ".equals(columnValue)&&columnValue!=null)
{
columnValue = " ' "+ columnValue+ " ' ";
}
}
if(columnName!=null&&columnName.indexOf( "DATE ")> 0)
System.out.println(columnValue);
}
public void endElement(String uri, String localName, String qName) throws SAXException {
if(! "DATA ".equals(qName)&&! "TABLE ".equals(qName))
{
if(! "LASTUPDATE ".equals(columnName))
{
sql += columnValue + ", ";
} <