postgre数据库连接问题!想要多少分就给多少!
奇怪的问题:
以下是我的代码片段:
try{
oStmt = oConn.createStatement();
String sSQL = "insert into test_table values('" + sContent + "')";
oStmt.executeUpdate(sSQL);
} catch(Exception e){
}finally{
if(oStmt != null){
try{
oStmt.close();
}catch(Exception e){
}
oStmt = null;
}
if(oConn != null){
try{
oConn.close();
}catch(Exception e){
}
oConn = null;
}
}
}
Connection 是从Tomcat的连接池中取得的。
sContent 是从网关接收的字符串,是一堆乱码,值为“GHOG^@:?UN9”。在执行SQL语句的时候抛出以下异常:
java.sql.SQLException: ERROR: parser: unterminated quoted string at or near "'GHOG" at character ……
在第二个数据库操作的时候就出现以下异常:
The backend has broken the connection. Possibly the action you have attempted has caused it to close.
在以后的数据库操作就出现以下异常:
An I/O error has occured while flushing the output - Exception: java.net.SocketException: Broken pipe
Stack Trace:
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:69)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:127)
at org.postgresql.PG_Stream.flush(PG_Stream.java:355)
at org.postgresql.core.QueryExecutor.sendQuery(QueryExecutor.java:139)
at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:63)
at org.postgresql.Connection.ExecSQL(Connection.java:451)
at org.postgresql.Connection.ExecSQL(Connection.java:434)
at org.postgresql.jdbc1.Statement.execute(Statement.java:111)
at org.postgresql.jdbc1.Statement.executeQuery(Statement.java:49)
.
.
.
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
at java.lang.Thread.run(Thread.java:536)
End of Stack Trace
只要出现了第三个异常,所有对数据库的操作都抛出这个异常,直到重启Tomcat。
请教各位高手,这是什么原因?如何解决?
万分感谢!