Announcement Announcement Module
Collapse
No announcement yet.
JdbcTemplate exception: Network error IOException: Address already in use Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JdbcTemplate exception: Network error IOException: Address already in use

    I am new to Spring framework.

    I am working on a data migration application.
    It reads each file in a folder, where each file contains around 1,600,000 rows
    and it inserts each row into a sql server 2000 database table.

    I am using JdbcTemplate's update function in a loop to insert data.
    I get exception (java.sql.SQLException: Network error IOException: Address already in use: connect) when I configure JdbcTemplate like this:

    <bean name="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
    <constructor-arg>
    <ref bean="dataSource" />
    </constructor-arg>
    </bean>
    <bean name="dataSource"
    class="org.springframework.jdbc.datasource.DriverM anagerDataSource"
    p:driverClassName="net.sourceforge.jtds.jdbc.Drive r"
    p:url="jdbc:jtds:sqlserver://localhost:1433/CreditMIS"
    p:username="sa"
    password="****" />

    But surprisingly the problem is gone if I configure JdbcTemplate like this:

    <bean name="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
    <constructor-arg>
    <ref bean="dataSource" />
    </constructor-arg>
    </bean>
    <bean name="dataSource" class="org.springframework.jdbc.datasource.SingleC onnectionDataSource"
    p:driverClassName="net.sourceforge.jtds.jdbc.Drive r"
    p:url="jdbc:jtds:sqlserver://localhost:1433/CreditMIS"
    p:username="sa"
    password="****" />


    Now, I don't understand why I get the exception when I use
    org.springframework.jdbc.datasource.DriverManagerD ataSource
    and what problem I may face further, because of using org.springframework.jdbc.datasource.SingleConnecti onDataSource
    instead of org.springframework.jdbc.datasource.DriverManagerD ataSource.

    Please let me know the best approach to solve the problem.

    The full exception is trace is as below:

    Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not get JDBC Connection; nested exception is java.sql.SQLException: Network error IOException: Address already in use: connect
    at org.springframework.jdbc.datasource.DataSourceUtil s.getConnection(DataSourceUtils.java:82)
    at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:552)
    at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:767)
    at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:825)
    at org.springframework.jdbc.core.JdbcTemplate.update( JdbcTemplate.java:829)
    at repository.DailyPositionDao.insert(DailyPositionDa o.java:78)
    at dmt.Loader.loadDailyPosition(Loader.java:81)
    at dmt.Main.main(Main.java:33)
    Caused by: java.sql.SQLException: Network error IOException: Address already in use: connect
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(C onnectionJDBC2.java:410)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(C onnectionJDBC3.java:50)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.ja va:184)
    at java.sql.DriverManager.getConnection(DriverManager .java:582)
    at java.sql.DriverManager.getConnection(DriverManager .java:154)
    at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnectionFromDriverManager(DriverMan agerDataSource.java:283)
    at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnectionFromDriverManager(DriverMan agerDataSource.java:271)
    at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnectionFromDriverManager(DriverMan agerDataSource.java:255)
    at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnection(DriverManagerDataSource.ja va:236)
    at org.springframework.jdbc.datasource.DataSourceUtil s.doGetConnection(DataSourceUtils.java:113)
    at org.springframework.jdbc.datasource.DataSourceUtil s.getConnection(DataSourceUtils.java:79)
    ... 7 more
    Caused by: java.net.BindException: Address already in use: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl .java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSoc ketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:366)
    at java.net.Socket.connect(Socket.java:525)
    at sun.reflect.GeneratedMethodAccessor2.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at net.sourceforge.jtds.jdbc.SharedSocket.createSocke tForJDBC3(SharedSocket.java:307)
    at net.sourceforge.jtds.jdbc.SharedSocket.<init>(Shar edSocket.java:257)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(C onnectionJDBC2.java:311)
    ... 17 more
Working...
X