I am fetching data from MySQL using JAVA JDBC driver.
Following exception is occurring:
"Communications link failure. The last packet successfully received
from the server was 14,380,298 milliseconds ago. The last packet sent
successfully to the server was 14,380,634 milliseconds ago.".
This error is occurring alternatively. That means if I run this for the first time no exception occur, but in the second time this exception occur. Then in the third run no exception give, in forth one again exception happen. I am using TimerTask to run the program every four hours.
Communication between the program and database works correctly when it run without exceptions.
Code is as follows:
public class CreatePO extends TimerTask {
public CreatePO() {
handler = new RFCHandler();
}
#Override
public void run() {
// TODO Auto-generated method stub
try {
System.out.println("Run Create PO");
getItemFromDB();
sendDataToSap();
} catch (Exception e) {
e.printStackTrace();
}
}
private void getItemFromDB() {
// TODO Auto-generated method stub
System.out.println("Run get items from DB");
Connection connection = null;
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(dateFormat.format(date));
String queryOne = "SELECT reference_no, vendor_acc_no, date, mat_no,"
+ "po_qty, po_unit_measure, rate, order_price_unit, plant, user_name, email_id "
+ "FROM tbl_po_data WHERE status <> 'X'";
try {
pooler = DBPool_POSMS.getInstance();
dataSource1 = pooler.getDataSource();
System.out.println("PO pooler");
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println(" : PO pooler error");
}
try {
connection = dataSource1.getConnection();
connection.setAutoCommit(false);
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery(queryOne);
int lineitem = 0;
rs.last();
rcount = rs.getRow();
rs.beforeFirst();
System.out.println("rcount = " + rcount);
System.out.println("PO while loop");
itemData = new Object[11][rcount];
if (rcount > 0) {
while (rs.next()) {
itemData[0][lineitem] = rs.getString("reference_no");
itemData[1][lineitem] = rs.getString("vendor_acc_no");
itemData[2][lineitem] = rs.getDate("date");
itemData[3][lineitem] = rs.getString("mat_no");
itemData[4][lineitem] = rs.getString("po_qty");
itemData[5][lineitem] = rs.getString("po_unit_measure");
itemData[6][lineitem] = rs.getString("rate");
itemData[7][lineitem] = rs.getString("order_price_unit");
itemData[8][lineitem] = rs.getString("plant");
itemData[9][lineitem] = rs.getString("user_name");
itemData[10][lineitem] = rs.getString("email_id");
lineitem = lineitem + 1;
}
rs.close();
st.close();
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
System.out.println(" : PO while loop error");
e1.printStackTrace();
} finally {
try {
connection.close();
System.out.println("Close connection one");
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println(" : Connection close error");
}
}
}
private void sendDataToSap() {
System.out.println("Send Data to Sap");
Table IT_LIST = null;
Table IT_RESPONSE = null;
try {
if (rcount > 0) {
}
}
} catch (Exception e) {
// TODO: handle exception
handler.releaseClient();
System.out.println(e + " : Handler release error");
}
finally {
rcount = 0;
}
}
Exception...
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 14,380,298 milliseconds ago. The last packet sent successfully to the server was 14,380,634 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3743)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2506)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4842)
at org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:371)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setAutoCommit(PoolingDataSource.java:328)
at CreatePO.getItemFromDB(CreatePO.java:84)
at CreatePO.run(CreatePO.java:53)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Caused by: java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3725)
... 10 more
The problem is that your connection was open too long and was closed by MySQL server (as indicated by the "Connection reset by peer: socket write error" in the stacktrace). You need to configure your connection pool to either close too old connections, validate (test) the connection before handing it out or a combination of that.
You could also try increasing the timeout configuration in MySQL, but to be honest, a connection that was open for close to 4 hours (14 million milliseconds) may just need to be closed.
Related
I've searched for a long time for this in here and other places, and could not find my answer:
As part of a project I require to make a set of Connection objects (SQL Server) to take and restore connections to (Connection pool).
My issue is how to manipulate the objects in the set:
When a client requests a Connection I can remove it from the set, and when he's finished - add it back (since it's all unique values anyway).
But I am having trouble with this.
edit:
My code runs to an issue:
Exception in thread "Thread-10" java.util.ConcurrentModificationException
at java.base/java.util.HashMap$HashIterator.nextNode(HashMap.java:1597)
at java.base/java.util.HashMap$KeyIterator.next(HashMap.java:1620)
at connectionUtilities.ConnectionPool.getConnection(ConnectionPool.java:105)
at main.Main$1.run(Main.java:22)
at java.base/java.lang.Thread.run(Thread.java:833)
at line:
connection = (Connection)iterator.next();
I firstly use a constructor to add 10 connections to the set:
public ConnectionPool() {
for (int i = 0; i <= 9; i++) {
try {
Class.forName(jdbcDriver);
System.out.println("driver loaded succesfully");
connection = DriverManager.getConnection(connectionUrl);
connectionSet.add(connection);
System.out.println("connection created succesfully.");
System.out.println("Connection id: " + connectionSet.iterator());
System.out.println("connections Final size= " + connectionSet.size());
this.counter++;
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println(connectionSet);
// String[] conPoolArray = connectionSet.toArray(new
// String[connectionSet.size()]);
}
Here is my getConnection method (iterator is declared in the class as):
Iterator iterator = connectionSet.iterator();
public Connection getConnection() {
synchronized (instance) {
if (!connectionSet.isEmpty()) {
connection = (Connection)iterator.next();
return connection;
} else {
try {
instance.wait();
instance.getConnection();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return connection;
}
I am receiving the java.util.ConcurrentModificationException error and I understand it's because I can't adjust the set while iterating over it.
Any suggestions?
Thanks up front!
Trying to do a rollback, when the rollback kicks in it throws an SQL Exception. What am I doing wrong??? I've checked the other posts but cant find anything to explain how to fix this. I've tried using savepoints and it says those are not able to be implemented. Do rollbacks always throw this error? Using MySQL Server and northwinds DB.
Stack Trace:
TESTING TRANSACTION FAILURE
Connecting to database at jdbc:mysql://localhost:3306/northwind ...
Connecting...
Checking for transaction support...
Beginning a transaction...
Looking up customer 'ACJO' ...
Connecting to database at jdbc:mysql://localhost:3306/northwind ...
Connecting...
select * from customers where CustomerID = ?
Found customer.
Adding a new order to the database...
> insert into orders(OrderDate) values(?)
> select OrderID from orders where OrderDate = ?
Updating an order...
> update orders set orders.BadField = ? where orders.OrderID = ?
**** Rolling back transaction ****
java.sql.SQLException: Unknown column 'orders.BadField' in 'field list'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2247)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1371)
at advanced.jdbc.northwind.TransactionDemo.updateOrderMistake(TransactionDemo.java:281)
at advanced.jdbc.northwind.TransactionDemo.testTransactionFailure(TransactionDemo.java:216)
at advanced.jdbc.northwind.TransactionDemo.main(TransactionDemo.java:425)
CODE:
public void testTransactionFailure() {
System.out.println("\n\nTESTING TRANSACTION FAILURE");
Connection connection = null;
try {
connection = getConnection();
System.out.println("Checking for transaction support...");
// TODO 04. Get the database metadata.
DatabaseMetaData databaseMetadata = connection.getMetaData();
// TODO 05. Determine if the database supports transactions.
boolean supported = false;
supported = databaseMetadata.supportsTransactions();
if (supported) {
System.out.println("Beginning a transaction...");
// TODO 06. Begin database transaction.
connection.setAutoCommit(false);
// create a new customer
String companyName = "ACME Products Ltd.";
String contactName = "John Doe";
String customerID = createCustomerID(contactName, companyName);
// check for customer before inserting
if (!customerExists(customerID)) {
addCustomer(customerID, companyName, contactName);
}
// add the order
int orderID = insertOrder(connection, customerID);
// oops, forgot shipping city so let's update it
updateOrderMistake(connection, orderID, "Timbuktu");
// TODO 07. Complete the transaction.
System.out.println("Committing");
connection.commit();
} else {
System.err.println("Transactions not supported!");
}
} catch (SQLException e) {
if (connection != null) {
System.out.println("**** Rolling back transaction ****");
// TODO 08. Roll back the transaction.
try {
connection.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
e.printStackTrace();
} finally {
try {
if (connection != null) {
// TODO 09. Release resources.
connection.close();
connection = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
I am getting this error from the database
Data source rejected establishment of connection, message from
server: "Too many connections"
I am closing my connections properly, I don't know why i am getting this error when my thread pool is only 5 and i think i am closing the connections. Anyone know why.
Below is my code. I have changed a few things to stay anonymous
public class myMain {
public static void main(String[] args) {
ExecutorService executor = Executors.newFixedThreadPool(5);
for (int i = 0; i < (569743 / 100); i++) {
try {
MyClass mclass = new MyClass();
executor.execute(mclass);
} catch (Exception e) {
e.printStackTrace();
}
}
executor.shutdown();
try {
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Finished all threads");
}
}
.
public class MyClass implements Runnable {
public MyClass(){
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost/mytable?" + "user=&password=");
}
public void run() {
try {
String sql = "My select STATEMENT";
PreparedStatement stmt = connect.prepareStatement(sql);
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
try {
int id = rs.getInt("movie_id");
String title = rs.getString("title");
int year = rs.getInt("year");
String trailerUrl = rs.getString("trailerUrl");
if (trailerUrl == null || (trailerUrl != null && trailerUrl.length() == 0)) {
YoutubeTrailerFetcher youtube = new YoutubeTrailerFetcher(title, year);
String trailer = youtube.getVideoId();
String updateSql = "my UPDATE Statement";
Statement updateStm = connect.createStatement();
updateStm.executeUpdate(updateSql);
updateStm.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
connect.close();
stmt.close();
rs.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
The main problem with your code is that you open a connection in the main thread, when calling the MyClass constructor, but the connection is only closed after the thread pool has finished executing the task. So you're trying to open 5697 connections, which is a whole lot. And these connections wait for being closed that one of the 5 threads in the pool has finished executing the task.
As I said in my comment: the method opening the connection should be the one closing it. And it should be closed in a finally block to ensure it is closed, whatever happens in the method, or better, you should use the try-with-resources statement to ensure that
Here I am using jdbcHelper to establish connection with database but some times(not all the times) I am getting exception as null pointer in connection establishment but that is not all the time.
here is my code.This code is used to insert data into database..
Connection conn = JDBCHelper.getConnection();
PreparedStatement ps1 = null;
System.out.println("In Side DATA BASE");
System.out.println("in side database deviceid=" + s);
System.out.println("in side database rfide=" + s1);
System.out.println("in side database longitude=" + lati);
System.out.println("in side database latitude= " + lot);
System.out.println("in side database datalength=" + data_length);
Date date = new Date();
java.sql.Timestamp dt = new java.sql.Timestamp(date.getTime());
int flag = 1;
System.out.println("date=" + dt);
System.out.println("flag=" + flag);
try {
String hql = "insert into gpsData1(dateTime,deviceid,latitude,longitude,rfid,flag,datalength) values(?,?,?,?,?,?,?)";
ps1 = conn.prepareStatement(hql);
ps1.setString(1, dt.toString());
ps1.setString(2, s);
ps1.setFloat(3, lati);
ps1.setFloat(4, lot);
ps1.setString(5, s1);
ps1.setInt(6, flag);
ps1.setInt(7, data_length);
ps1.executeUpdate();
conn.commit();
System.out.println("DATA BASE Inserting Completed");
} catch (Exception ex) {
ex.printStackTrace();
} finally {
JDBCHelper.close(ps1);
JDBCHelper.close(conn);
}
This is my JDBC code..
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class JDBCHelper {
public static final String url = "jdbc:mysql://localhost:3306/treamisdemo";
public static final String uid = "root";
public static final String pwd = "myserver";
/**
* #param
* args
*/
static {
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("connection is sucessful");
} catch (ClassNotFoundException e) {
System.err.println("ERROR: failed to load mysql JDBC driver.");
e.printStackTrace();
}
}
public static void close(ResultSet c) {
try {
if (c != null) {
c.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void close(Statement c) {
try {
if (c != null) {
c.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void close(Connection c) {
try {
if (c != null) {
c.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public static Connection getConnection() {
Connection con = null;
try {
con = DriverManager.getConnection(url, uid, pwd);
System.out.println("obtain connection =" + con);
con.setAutoCommit(false);
return con;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
}
This is the stack trace..
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data sourc
e rejected establishment of connection, message from server: "Too many connecti
ons"
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1128)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2336)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2
369)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.GeneratedConstructorAccessor39.newInstance(Unknown Source
)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:305)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at com.treamis.transport.vehicle.JDBCHelper.getConnection(JDBCHelper.jav
a:71)
at com.treamis.transport.vehicle.MyTimerTask.getRoutePointList(MyTimerTa
sk.java:639)
at com.treamis.transport.vehicle.MyTimerTask.sendSms(MyTimerTask.java:10
8)
at com.treamis.transport.vehicle.MyTimerTask.run(MyTimerTask.java:71)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
The exception states: "Too many connections"
You must close every connection after you finished using it.
Sometimes you don't close the connection you open. You should move getConnection call inside the try block so you will always close if in finally statement.
Another possible reason is that you try to connect too many times simultaneously.
Suggestions:
The connection should be opened only when needed. No need to open it immediately at the beginning of the function.
The NPE you get is because getConnection() returns null on error. I think it is better to throw an exception in this case rather than return null.
If you use Java 7, you can use try-with-resources to close resources after finished using them.
Make sure you use reasonable amount of DB connections. If you need more than available connection, consider using one connection for all your DB accesses.
You can use a single connection for this Timer task. Commit on sucessful update but dont close the connection, reuse it.
Something like this:
boolean doInsert(){
// your insert code
// String hql = "insert into gpsData1(dateTime,deviceid,latitude,longitude,rfid
return ps1.executeUpdate(); // this returns true or false
}
boolean isInsert = doInsert();
if(isInsert){
conn.commit();
}
Use a real connection pool like HikariCP or BoneCP.
Hi All
I am trying to connect a data base. below i have given the code. I am able to connect to data base but unable to connect 2nd time if difference between 1st time and 2nd time is greater then "wait time out" of mysql data base.
I am using mysql data base. I am getting "Communications link failure" problem
wait_timeout is 10 sec (for convenience) it is 8 hour for my DB
I am giving you code
public class DatabaseManager {
private static Connection jConn;
private static DatabaseManager manager;
public Boolean getUser(){
Statement jStmt = null;
ResultSet rs = null;
try {
String query = "SELECT * FROM USER ";
System.out.println(query);
jStmt = jConn.createStatement();
rs = jStmt.executeQuery(query);
while (rs.next()) {
}
}catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
public static synchronized DatabaseManager getInstance() {
if (manager == null) {
try {
manager = initialize();
} catch (DatabaseInitializationException e) {
// e.printStackTrace();
// throw new RuntimeException("Database Initialization
// Exception");
}
}
return manager;
}
private static DatabaseManager initialize()
throws DatabaseInitializationException {
try {
Class.forName(serverSrv.readPropertyValue("Srver_Path",
"DBdriver"));
} catch (ClassNotFoundException e) {
throw new DatabaseInitializationException(e.getMessage());
}
try {
jConn = DriverManager.getConnection("DB_URL","user","password");
System.out.println("Excecuted initialize() for Database ");
} catch (SQLException e) {
throw new DatabaseInitializationException(e.getMessage());
}
return new DatabaseManager();
}
}
AND I am testing like
public static void main(String[] args) {
long st = System.currentTimeMillis();
long end ;
DatabaseManager dm = DatabaseManager.getInstance();
if( dm.getUser() )
System.out.println("success");
else
System.out.println("failed..");
do{
end = System.currentTimeMillis();
}while( (end-st)<12*1000 );
if( dm.getUser() )
System.out.println("success");
else
System.out.println("failed..");
}
and it is giving exception like
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2873)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2763)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3299)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1837)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1961)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2537)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2466)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1383)
at mypackage.db.DatabaseManager.getUser(DatabaseManager.java:127)
at mypackage.test.Test.main(Test.java:23)
Caused by: java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160)
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2329)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2774)
Perhaps you should close the ResultSet as well as Statement.
This link has some tips on doing this correctly.
Your problem is that you are trying to reuse jConn which closes automatically after a timeout. So when you try and use it again an exception is thrown. Depending on what you are trying to do i would suggest (for simplicity) ..
Closing jConn by typeing jConn.close();
Then When you need to use the db again reconnect using jConn = DriverManager.getConnection("DB_URL","user","password");
Check your connection time out settings.