mysql使用命名管道,Java MySQL-命名管道连接在关闭时引发警告

I am connecting to MySQL in Java with Connector/J using Named Pipes. My connection and query are successful, but I am receiving a warning when I try to close the connection. I would like to know what I should do to fix whatever is causing the warning other than removing connection.close() (or removing the try-with-resources connection block and not adding a connection.close()).

Here is my code for the query:

public static List QueryDB(int RowValue) {

List ValueList = new ArrayList();

try {

try (Connection Connection_T = MySQLConnectionResources.createConnection()) {

try (Statement Statement_T = Connection_T.createStatement()) {

String String_T = "SELECT AColumn FROM ATable WHERE BColumn = " + RowValue + ";";

try (ResultSet ResultSet_T = Statement_T.executeQuery(String_T)) {

while (ResultSet_T.next()) {

ValueList.add(ResultSet_T.getLong("AColumn"));

}

}

}

}

} catch(SQLException SQLException_P) {

System.err.println("ERROR: Failed to query the database.");

ValueList.clear();

}

List Result_M = new ArrayList();

Result_M.add(ValueList);

return Result_M;

}

"MySQLConnectionResources" is just a custom class with method "createConnection()". There is nothing special to the class/method; it just creates and returns a connection.

After the method is completed (or technically, after the Java 7 try-with-resources connection block is completed) I receive the following error/warning:

Thu Sep 22 00:31:54 EDT 2011 WARN: Caught while disconnecting...

EXCEPTION STACK TRACE:

** BEGIN NESTED EXCEPTION **

java.net.SocketException

MESSAGE: Socket is not connected

STACKTRACE:

java.net.SocketException: Socket is not connected

at java.net.Socket.shutdownInput(Socket.java:1456)

at com.mysql.jdbc.MysqlIO.quit(MysqlIO.java:1687)

at com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4368)

at com.mysql.jdbc.ConnectionImpl.close(ConnectionImpl.java:1557)

at ... my class/method here (my class.java:#)

** END NESTED EXCEPTION **

If I remove the try-with-resources block (and don't add a connection.close()), the warning never appears. Also, if I switch to a TCP/IP connection the error never appears. BUT, neither of these solutions are satisfactory for my case. I want to ensure that the connection is properly closed and I will be using named pipe connections.

Any ideas?

-- (edit) --

Also: The error is being thrown by the Log within Connector/J. My error catching has nothing to do with how the error is being caught and printed. I've tried to research how to disable the WARN problems and have it print out just SEVERE problems (within Connector/J's Log), but I was unsuccessful. Furthermore, I would like to fix the WARN problem rather than ignore/conceal it.

-- (edit 2) --

I monitored the MySQL database and the connections aren't being closed. If I use a TCP/IP connection string rather than my named pipe connection string (and don't change anything else) the connection is closed just fine.

-- (edit 3) --

Ignoring my original code... just try the code below and it throws the warning. Seems like a bug to me.

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

public final class main {

public static void main(String[] args) {

Connection conn = null;

try {

conn =

DriverManager.getConnection("jdbc:mysql:///database?socketFactory=com.mysql.jdbc.NamedPipeSocketFactory&namedPipePath=\\\\.\\Pipe\\mysql.sock",

"root", "password");

conn.close();

} catch (SQLException ex) {

// handle any errors

}

}

}

解决方案

As it appears to be a bug, I have submitted an official bug report to the MySQL bugs forum.

I will post back here whenever I receive an update.

UPDATE:

My bug report was analyzed by MySQL coders. They believe it is a JAVA bug.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值