Results 1 to 6 of 6

Thread: spring jdbcTemplate DriverManager Exception

  1. #1
    Join Date
    Jun 2007
    Posts
    20

    Default 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. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

    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
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    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 at 04:02 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  4. #4
    Join Date
    Jun 2007
    Posts
    20

    Default

    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
    Attached Files Attached Files

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    I would check the connection configuration, it seems like there is a problem with connecting.
    Last edited by karldmoore; Aug 27th, 2007 at 04:01 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  6. #6
    Join Date
    Aug 2004
    Posts
    1,110

    Default

    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/
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •