Announcement Announcement Module
Collapse
No announcement yet.
Strange exception thrown when using a prepared statement Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Strange exception thrown when using a prepared statement

    Greetings:

    I am using the JDBC tools for putting data into a HSQLDB database. I am attempting to use a prepared statement to add information to a table in my database.

    The add code is shown below:

    public boolean addNewCustomer(Customer theCst)
    {
    boolean ret = false;
    String sql = "insert into registered_users (userid,firstname,middle,lastname,address1,address 2,city,state,zip,mainphone,altphone,email,type,goo d,hasorders) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    Object[] params = {new Integer(1),
    theCst.getCstName().getFirstName(),
    theCst.getCstName().getMidInitial(),
    theCst.getCstName().getLastName(),
    theCst.getCstAddress().getFirstStreet(),
    theCst.getCstAddress().getSecondStreet(),
    theCst.getCstAddress().getTheCity(),
    theCst.getCstAddress().getTheState(),
    theCst.getCstAddress().getZipCode(),
    theCst.getCstContact().getHomePhone().getFormatted Number(),
    theCst.getCstContact().getOtherPhone().getFormatte dNumber(),
    theCst.getCstContact().getEmailAddress(),
    new Integer(1),
    new Boolean(true),
    new Boolean(false)
    };
    JdbcTemplate tpl = new JdbcTemplate(getDataSource());
    try
    {
    tpl.update(sql,params);
    ret = true;
    }
    catch(Exception exc)
    {
    exc.printStackTrace();
    }
    return(ret);
    }

    I have a proper configuration that enables the JdbcTemplate to connect to the data source (and the HSQLDB database is running). The context file is given below:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <bean id="datastore" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName">
    <value>org.hsqldb.jdbcDriver</value>
    </property>
    <property name="url">
    <value>jdbc:hsqldb:hsql://localhost:9001/aspen_db</value>
    </property>
    <property name="username">
    <value>sa</value>
    </property>
    </bean>

    <bean id="handler" class="aspen.dbase.CustomerHandlerImpl">
    <property name="dataSource">
    <ref bean="datastore" />
    </property>
    </bean>
    </beans>

    Note that CustomerHandlerImpl is the class that contains the add method given previously.

    Everything looks OK, except that when I run a test on the code I get the following exception:

    org.springframework.jdbc.UncategorizedSQLException : (executing PreparedStatementCallback [org.springframework.jdbc.core.JdbcTemplate$SimpleP reparedStatementCreator@b9b538]): encountered SQLException [The table's data source for has not been defined in statement [insert into registered_users (userid,firstname,middle,lastname,address1,address 2,city,state,zip,mainphone,altphone,email,type,goo d,hasorders) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)]]; nested exception is java.sql.SQLException: The table's data source for has not been defined in statement [insert into registered_users (userid,firstname,middle,lastname,address1,address 2,city,state,zip,mainphone,altphone,email,type,goo d,hasorders) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)]
    java.sql.SQLException: The table's data source for has not been defined in statement [insert into registered_users (userid,firstname,middle,lastname,address1,address 2,city,state,zip,mainphone,altphone,email,type,goo d,hasorders) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)]
    at org.hsqldb.jdbc.jdbcUtil.throwError(Unknown Source)
    <other lines in the stack trace omitted>

    I have done several debugging sessions, and the above exception gets thrown *after* spring connects to the database. In fact, it gets thrown when the HSQLDB connection object calls its prepareStatement() method.

    It is almost as if the insert statement is missing information about the data source for the table -- except that the insert statement, as defined, is the correct syntax, even for HSQLDB! Spring is apparently finding the data source without problems. I cannot figure out why this exception is being thrown.

    Can someone please advise???

    -Factor Three
Working...
X