Last active
January 26, 2016 15:59
-
-
Save systemhalted/228bca91f7c5ce74cba0 to your computer and use it in GitHub Desktop.
InsertClob
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package in.palakmathur; | |
import java.sql.Clob; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.PreparedStatement; | |
import java.util.Hashtable; | |
import javax.naming.Context; | |
import javax.naming.InitialContext; | |
import javax.sql.DataSource; | |
public class InsertCLOB { | |
private static final String DS_NAME = "esi.config.ds"; | |
public InsertCLOB() { | |
} | |
private static String printStackTrace(Exception e) { | |
java.io.ByteArrayOutputStream baOutputStream = new java.io.ByteArrayOutputStream(); | |
e.printStackTrace(new java.io.PrintStream(baOutputStream)); | |
return baOutputStream.toString(); | |
} | |
private static Connection getConnection() throws Exception { | |
DataSource ds = getLocalDataSource(DS_NAME); | |
return ds.getConnection(); | |
} | |
private static Connection getConnection(String dsName) throws Exception { | |
DataSource ds = getLocalDataSource(dsName); | |
return ds.getConnection(); | |
} | |
private static DataSource getLocalDataSource(String name) throws Exception { | |
Context ctx = new InitialContext(); | |
DataSource ds = (DataSource) ctx.lookup(name); | |
return ds; | |
} | |
public static String insertCLOB(String dsName, | |
String transactionID, String xmlResponse) { | |
String status = "FAILURE"; | |
try { | |
Connection conn = InsertCLOB.getConnection(dsName); | |
String sql = "insert into clob_table (transaction_id, xml_response, in_time) values (?,xmltype(?),TO_DATE(SYSDATE,'DD-MON-RR'))"; | |
PreparedStatement prepStatement = conn.prepareStatement(sql); | |
prepStatement.setLong(1, Long.valueOf(transactionID).longValue()); | |
Clob xmlResp = conn.createClob(); | |
xmlResp.setString(1, xmlResponse); | |
prepStatement.setClob(2, xmlResp); | |
prepStatement.executeUpdate(); | |
conn.close(); | |
status = "SUCCESS"; | |
} catch (Exception e) { | |
status = "FAILURE at " + e.getMessage(); | |
} | |
return status; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment