Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Simple JDBC problem reading clob from Oracle - throwing issue in Win 7

921770Mar 5 2012 — edited Mar 5 2012
Hi

I have a simple java program which connects to an Oracle 11g database using the JDBC thin driver. I goes into a hanging state and throws IO exception after 30 minutes or so.

Specific details are give below

JDK version - JDK 1.6_24 which comes along with weblogic (specific path - D:\Applns\Oracle\Middleware\jdk160_24)
Thin driver - the latest ojdbc6_g.jar downloaded from the Oracle website
Operation - a simple read operation of a Clob column from the Oracle database
Database version - 11g
Program - please find it attached

I am running it on Windows 7 Enterprise edition. When i run the same code from a Windows XP box, its working perfectly fine. Since I am using the same driver in both the places, the point of suspicion leads to the JDK. In both the boxes, weblogic is installed(same version) and JDK being used is the one that comes bundled with weblogic.

Any pointers to this issue? I am going to download the latest JDK 1.6 version and try again from both the boxes.

The java sample program is given below. In fact I had faced this issue while running the application in Weblogic, thats the reason why i have opted to run the sample program. Luckily i was able to reproduce the same.

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JDBCClobTest {

private Connection connection;

public void initialize() throws SQLException {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
connection = DriverManager.getConnection(
"jdbc:oracle:thin:@IP:1521:DEV",
"D_DESIGN", "D_DESIGN");
}

private void readClob(int paId, String meContext, String location) throws SQLException {
try {
long startTime = System.currentTimeMillis();
int count = 0;
String sql = "SELECT * from ENODEB where PAID = ? AND MECONTEXT = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setInt(1, paId);
stmt.setString(2, meContext);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
paId = resultSet.getInt("PAID");
System.out.println("paId:"+paId);
meContext = resultSet.getString("MECONTEXT");
System.out.println("meContext:"+meContext);
String subNetwork = resultSet.getString("SUBNETWORK");
System.out.println("subNetwork:"+subNetwork);
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(location)));
Reader reader = resultSet.getCharacterStream("MECONTEXTVSDATACONTAINER");
System.out.println("reader:"+reader);
BufferedReader buffReader = new BufferedReader(reader);
System.out.println("buffReader:"+buffReader.toString());
//String line;
System.out.println("Starting to read the stream");
//StringBuilder builder = new StringBuilder();
int charact = -1;
while ((charact = buffReader.read()) != -1) {
count++;
System.out.println("Inside while loop");
writer.write(charact);
}
writer.flush();
writer.close();
buffReader.close();
System.out.println("Exiting the function, finished reading the clob");
}
long endTime = System.currentTimeMillis();
System.out.println("Total characters:"+count);
System.out.println("Total time taken:"+((endTime-startTime)/1000));
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (connection != null && !connection.isClosed()) {
connection.close();
}
}
}

public static void main(String args[]) {
int paId = Integer.parseInt(args[0]);
String meContext = args[1];
String location = args[2];
JDBCClobTest clobeTest = new JDBCClobTest();
try {
clobeTest.initialize();
clobeTest.readClob(paId, meContext,location);
} catch (SQLException e) {
e.printStackTrace();
}
}
}


Best Regards
SS
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 2 2012
Added on Mar 5 2012
1 comment
1,156 views