Hi,
     i was working on the SAX parser with JDBC and was
using jaxp1.1 parser.I had coded a simple program that
prints a "insert" statement.It worked fine
Later i added SQL statements to the existing code for
making transactions to the Database.When executing i
got the insert statement printed but also the
following error:
*******************************************************
C:\Thesis\CSESAM>java insProg
In the startDocument fn
In the startElement fn
Start Element: OPERATIONS
In the startElement fn
Start Element: INSERT
In the startElement fn
Start Element: TABLENAME
TABLENAME : csesamSample
Start 94 , Length 12
In the End Element
End Element: TABLENAME
In the startElement fn
Start Element: VAL
VAL : "9999"
Start 123 , Length 6
In the End Element
End Element: VAL
In the End Element
End Element: INSERT
In the End Element
End Element: OPERATIONS
The insert statement is as follows: insert into
csesamSample values ("9999");
Exception in thread "main"
java.lang.NullPointerException
        at
org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:523)
        at
org.apache.crimson.parser.Parser2.parse(Parser2.java:304)
        at
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)
        at insProg.insProc(insProg.java:54)
        at insProg.main(insProg.java:43)
*******************************************************

PLEASE HELP ME OUT.I've attached the program code too
below....
*******************************************************
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.Locator;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import java.sql.*;
import java.net.*;

public class insProg extends DefaultHandler
{

        private int count = 0;
        String tempElement = " ";
        String insStmnt = " ";
        String delStmnt = " ";
        String updStmnt = " ";
        Connection conn;

        public void insProg()
        {
                String url = "jdbc:odbc:csesam";
                try
                {
                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                        conn = DriverManager.getConnection(url);
                }
                catch(ClassNotFoundException e)
                {
                        System.out.println("Class Exception "+e);
                }
                catch(SQLException e)
                {
                        System.out.println("Class Exception "+e);
                }
        }

        public static void main(String args[]) throws
Exception
        {
                insProg c1 = new insProg();
                c1.insProc();
        }
        public void insProc() throws Exception
        {
                XMLReader xmlreader = null;
                SAXParserFactory spFactory =
SAXParserFactory.newInstance();
                spFactory.setValidating(false);
                SAXParser spParser = spFactory.newSAXParser();
                xmlreader = spParser.getXMLReader();
                xmlreader.setContentHandler(this);
                InputSource source = new
InputSource("C:/Thesis/Csesam/csesam_sample.xml");
                xmlreader.parse(source);
        }
        public void startDocument() throws SAXException
        {
                System.out.println("In the startDocument fn");
        }
        public void startElement(String namespURI , String
name , String qname , Attributes atts) throws
SAXException
        {
                System.out.println("In the startElement fn");
                System.out.print("Start Element: ");
                System.out.println(name);
                tempElement = name;
                if(tempElement == "INSERT")
                        insStmnt = "insert into ";
        }
        public void endElement(String namespURI , String name
, String qname)
        {
                System.out.println("In the End Element");
                System.out.print("End Element: ");
                System.out.println(name);
        }
        public void characters(char[] ch,int start,int
length) throws SAXException
        {
                System.out.print(tempElement+ " : ");
                System.out.println(new String(ch,start,length));
                System.out.println("Start "+start+" , "+"Length
"+length);
                if(tempElement == "TABLENAME")
                        insStmnt = insStmnt + new String(ch,start,length);
                else if(tempElement == "VAL")
                {
                        insStmnt = insStmnt + " values (" + new
String(ch,start,length);
                        insStmnt = insStmnt + ");";
                }
        }

        public void endDocument() throws SAXException
        {
                  String tempStmnt;
                  try
                  {
                        System.out.println("The insert statement is as
follows: "+insStmnt);
                        PreparedStatement stmnt =
conn.prepareStatement(insStmnt);
                        stmnt.executeUpdate();
                        conn.close();
                  }
                  catch(SQLException e)
                  {
                        System.out.println("Class Exception "+e);
                  }
        }
}



__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

---------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to