Announcement Announcement Module
No announcement yet.
Problem setting the datasource Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem setting the datasource

    I have a problem with creating the datasource using Spring JBDC to a Derby database. Can anybody help please

    The start of the code to create the data source is:

    package delegate;

    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    import javax.sql.DataSource;
    import javax.swing.JOptionPane;

    import org.springframework.jdbc.core.namedparam.MapSqlPar ameterSource;
    import org.springframework.jdbc.core.namedparam.NamedPara meterJdbcTemplate;
    import org.springframework.jdbc.core.namedparam.SqlParame terSource;
    import org.springframework.jdbc.core.simple.SimpleJdbcIns ert;
    import org.springframework.jdbc.core.*;

    import org.springframework.jdbc.datasource.*;

    import org.springframework.jdbc.object.*;


    import javax.sql.*;

    public class DelegateAdmin {
    private static final String QUERY = "select * from delegate";
    private static final String UPDATE = "update delegate set jobtitle = :jobtitle where name = :name";
    private static final String DELETE = "delete from delegate where name=:name";
    private static final String TITLE = "Delegate Admin";
    private static final String GET_NAMES = "select name from delegate";
    private static final String DELETE_ALL = "delete from delegate";
    private SimpleJdbcInsert insertActor;
    private String[] inputOptions = {"Insert", "Update", "List", "Delete", "Delete All"};
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    public void setDataSource(DataSource dataSource) {
    namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
    insertActor = new SimpleJdbcInsert(dataSource).withTableName("delega te").usingGeneratedKeyColumns("id");;

    The XML configuration file contains:

    <bean id="delegateadmin" class="delegate.DelegateAdmin">
    <property name="dataSource" ref="dataSource" />

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" />
    <property name="url" value="jdbc:derby:MyDB;create=true" />

    The error message is:

    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSource' defined in class path resource [delegate.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateExcep tion; nested PropertyAccessExceptions (1) are:
    PropertyAccessException 1: org.springframework.beans.MethodInvocationExceptio n: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [org.apache.derby.jdbc.EmbeddedDriver]
    at AutowireCapableBeanFactory.applyPropertyValues(Abs
    at AutowireCapableBeanFactory.populateBean(AbstractAu
    at AutowireCapableBeanFactory.doCreateBean(AbstractAu