Consultor Eletrônico



Kbase P187033: How to store a CLOB using JDBC?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/3/2011
Status: Unverified

GOAL:

How to store a CLOB using JDBC?

GOAL:

How to store an image file in a CLOB field?

FACT(s) (Environment):

All Supported Operating Systems
OpenEdge 10.x

FIX:

The following steps will generate a java program that will insert an image in a table in a Progress database:
1. Create a new or use an existing database.
2. Using the Data Dictionary create a table as follows:
field1: id integer
field2: cFile clob (100M)
3. Copy/Paste the following code in your editor:
import java.sql.*;
import java.io.*;
class SolutionSample {
public static void main(String[] args) throws SQLException {
Connection connection = null;
String connectionURL = "jdbc:datadirect:openedge://localhost:<db_port>;databaseName=<database_name>";
ResultSet rs = null;
PreparedStatement psmnt = null;
FileInputStream fis;
try {
Class.forName("com.ddtek.jdbc.openedge.OpenEdgeDriver").newInstance();
connection = DriverManager.getConnection(connectionURL, "<user>", "<password>");

File data = new File("<image+name>");
psmnt = connection.prepareStatement
("insert into pub.<table_name>(id,cFile) "+ "values(?,?)");
psmnt.setInt(1,10);
FileReader reader = new FileReader(data);
psmnt.setCharacterStream(2, reader, (int) data.length());
int s = psmnt.executeUpdate();
if(s>0) {
System.out.println("Uploaded successfully !");
}
else {
System.out.println("unsucessfull to upload image.");
}
}
catch (Exception ex) {
System.out.println("Found some error : "+ex);
}
finally {
connection.close();
}
}
}
** Make sure to replace your own values in the code.
5. Save and close editor.
6. Make sure CLASSPATH AND PATH variables are set for openedge.jar and java/bin directory.
7. Compile and run it.