Software caused connection abort: socket write error Again

Hello experts,

I have conclude that this exception happens becuase i use datasource mode in my applications and the database in the weekend is shut down for  the backup. so i need to restart the tomcat to initiate the connection again with the database.

is this logical ?

any way , i will ask to schedule database shutdown to re produce the error
Web_AdminAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
its more likely because you are using a connection pool
what you can do is configure the pool to validate a connection before using it and/or just create a new one if there is a failure reusing an existing one
0
 
objectsCommented:
that would make sense, if the database is shutdown your going to get exception trying to talk to it
0
 
Web_AdminAuthor Commented:
objects
i got the exception in the application using datasource mode which is database connection on the server level. if the server lost the connection due to the shutdown, i need to restart the server to initiate the connection

hope my boss will be happy with this conclusion :D
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Web_AdminAuthor Commented:

I think if i change the connection to driver mode or pool mode won't get this exception.

what jdbc mode should i go for ?
0
 
Web_AdminAuthor Commented:
objects:

so how i can do this? change in the configuration ?
0
 
objectsCommented:
possibly, depends on what connection  pool you are using
0
 
Web_AdminAuthor Commented:
i use this one:


<Resource name="jdbc/myoracle" auth="Container"
              type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
              url="jdbc:oracle:thin:@127.0.0.1:1521:mysid"
              username="scott" password="tiger" maxActive="20" maxIdle="10"
              maxWait="-1"/>



	

Context initContext = new InitialContext();
Context envContext  = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
Connection conn = ds.getConnection();

Open in new window

0
 
objectsCommented:
looks like you're not using a connection pool
does your application keep connections open? If so, then what you need to do when you get this exception is try and get a new connection. Though if the database is down you're going to need some logic so it doesn't sit there repeatedly trying to get a connection.
0
 
Pramod KumarCommented:
before using connection, you must check if it is open or closed


public Connection getConnection() {
	Context initContext = new InitialContext();
	Context envContext  = (Context)initContext.lookup("java:/comp/env");
	DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
	Connection conn = ds.getConnection();
	return conn;
}
.
.
.
//before using the connection object
if(conn.isClosed()){
 conn = getConnection();
}

Open in new window

0
 
Web_AdminAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.