Announcement Announcement Module
Collapse
No announcement yet.
spring jdbcTemplate DriverManager Exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring jdbcTemplate DriverManager Exception

    Hi,

    i used spring framework jdbctemplate,its working but some times it throws exception in DriverManager connection exception.

    Oracle10g database.I used SpringConfig.xml for read the database.I put this xml in WEB-INF/classes/SpringConfig.xml.

    did any one face this paroblem?what is the solution?please help me.


    public Collection findAll() throws RemoteException {
    ApplicationContext ctx=new ClassPathXmlApplicationContext("SpringConfig.xml") ;
    dataSource = (DataSource)ctx.getBean("mydataSource");
    JdbcTemplate jt = new JdbcTemplate(dataSource); String sql = "select EMPID,FIRSTNAME,LASTNAME from EMPLOYEE order by FIRSTNAME";
    return jt.query(sql,new EmployeeTOMapper());
    }

    public class EmployeeTOMapper implements RowMapper {
    public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
    Integer empId = new Integer(rs.getInt("EMPID"));
    String FirstName = rs.getString("FIRSTNAME");
    String LastName = rs.getString("LASTNAME");
    Employee empTo = new Employee(empId,FirstName,LastName);
    return empTo;
    }
    }

    Error Occur in this line

    return jt.query(sql,new EmployeeTOMapper());

    org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not get JDBC Connection; nested exception is java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169869568)(ERR=1 2519)(ERROR_STACK=(ERROR=(CODE=12519)(EMFI=4))))
    Caused by: java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169869568)(ERR=1 2519)(ERROR_STACK=(ERROR=(CODE=12519)(EMFI=4))))

    please help me..

    Thanks in advance
    Mahe

  • #2
    pls ude code tags

    i am not in my home to test some codes, maybe this is can be useless, but i see this

    Code:
    public Collection findAll()
    Code:
    return jt.query(sql,new EmployeeTOMapper());
    now in the other side
    Code:
    public Object mapRow
    you return one object, not a collection

    check the detail

    by other hand

    Code:
    Could not get JDBC Connection; nested exception is java.sql.SQLException: Io exception:
     Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169869568)(ERR=1 2519)(ERROR_STACK=(ERROR=(CODE=12519)(EMFI=4))))
    
    Caused by: java.sql.SQLException: Io exception: Connection
    share your bean xml definition, maybe some detail missing exists there

    THT

    regards

    Comment


    • #3
      You are creating a new ApplicationContext every time you call this method, that's not a good idea. As the exception says, it could get a connection. Is the configuration correct?
      Code:
      ApplicationContext ctx=new ClassPathXmlApplicationContext("SpringConfig.xml") ;
      dataSource = (DataSource)ctx.getBean("mydataSource");
      Last edited by karldmoore; Aug 27th, 2007, 04:02 PM.

      Comment


      • #4
        this my xml file

        <?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="mydataSource"
        class="org.springframework.jdbc.datasource.DriverM anagerDataSource"
        destroy-method="close">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="url" value="jdbc:oracle:thin:@221.134.108.197:1521:XE"/>
        <property name="username" value="news"/>
        <property name="password" value="news123"/>
        </bean>

        </beans>


        I am using separate class to get connection and call the instance each method,my class method for getting connection,

        public JdbcTemplate getjt() throws RemoteException {
        ApplicationContext ctx=new ClassPathXmlApplicationContext("SpringConfig.xml") ;
        dataSource = (DataSource)ctx.getBean("mydataSource");
        JdbcTemplate jt = new JdbcTemplate(dataSource);
        return jt;
        }

        is not correct means please tell me the correct way of getting connection.
        and call this method in my implementation is,

        private JdbcTemplate jt;
        private DataSource dataSource = null;
        dbconnect conn=new dbconnect();
        public Collection findAll() throws RemoteException {
        jt=conn.getjt();
        String sql = "select EMPID,FIRSTNAME,LASTNAME from EMPLOYEE order by FIRSTNAME";
        return jt.query(sql,new EmployeeTOMapper());
        }

        public class EmployeeTOMapper implements RowMapper {
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
        Integer empId = new Integer(rs.getInt("EMPID"));
        String FirstName = rs.getString("FIRSTNAME");
        String LastName = rs.getString("LASTNAME");
        Employee empTo = new Employee(empId,FirstName,LastName);
        return empTo;
        }
        }


        EMPLOYEE is class for only getter setter.yes return "object" but
        return jt.query(sql,new EmployeeTOMapper()); returns LIST or Collections,so its working but sometimes return the exception i couldn't catch the exception,because i debug it's work but run it shows exception again refresh its works sometime throws error.

        org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not get JDBC Connection; nested exception is java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169869568)(ERR=1 2519)(ERROR_STACK=(ERROR=(CODE=12519)(EMFI=4))))
        Caused by: java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169869568)(ERR=1 2519)(ERROR_STACK=(ERROR=(CODE=12519)(EMFI=4))))

        did any knows the reason of this exception.please help me...

        herewith,i have attached my class files.

        Thanks in advance,
        Mahe

        Comment


        • #5
          I would check the connection configuration, it seems like there is a problem with connecting.
          Last edited by karldmoore; Aug 27th, 2007, 04:01 PM.

          Comment


          • #6
            Looks like you are using Oracle XE - you might need to increase some resources on the database server:

            alter system set processes=150 scope=spfile;
            alter system set sessions=100 scope=spfile;

            Take a looke at this blog that discusses similar issues: http://paulcondran.com/2007/05/22/or...ource-problem/

            Comment

            Working...
            X