DBhelper
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
public class Connection {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
java.sql.Connection con =null;
ResultSet rs =null;
PreparedStatement ps =null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
/* local ssilx54 connection*/
// con = DriverManager.getConnection("jdbc:oracle:thin:@Xxx.xx.xx.xxx:xxxx:OraBE","schemaname","schemapwd");
/* OraBE connection */
con = DriverManager.getConnection("jdbc:oracle:thin:@TEORABE:2483:OraBE","schemaname","schemapwd");
/* OraBE connection */
// con = DriverManager.getConnection("jdbc:oracle:thin:@TEORABE:2483:OraBE","schemaname","schemapwd");
/* OraNDR connection */
// con = DriverManager.getConnection("jdbc:oracle:thin:@172.20.20.130:2487:OraNDR","svil_cg","svil_cg");
StringBuffer listQuery = new StringBuffer();
listQuery.append(" SELECT DISTINCT (columnname) FROM table1 WHERE ID IN ( SELECT DISTINCT(coulmnname) FROM TI_table2 WHERE CONTOCORRENTEID = ? )");
PreparedStatement ps1 = con.prepareStatement(listQuery.toString());
ps1.setLong(1,3607011);
rs = ps1.executeQuery();
while(rs.next()){
System.out.println("==="+rs.getLong("CONTOTITOLIID"));
}
Collection linkedCTCollection = new ArrayList();
System.out.println("======"+linkedCTCollection.size());
// to call proccedure or function
PreparedStatement ps1 = con.prepareStatement("select id,content from test_radeox where id=? ");
CallableStatement call = con.prepareCall("{ call ? :=AN_FN_XXXXXX(?) }");
call.registerOutParameter(1,Types.VARCHAR);
call.setLong(2,1200284);
call.execute();
System.out.println("======"+call.getString(1));
// for clob object
/* ps1.setInt(1,1);
rs = ps1.executeQuery();
String dbContent = null;
while(rs.next()){
dbContent = rs.getClob(2).getSubString(1,(int)rs.getClob(2).length());
}
System.out.println(dbContent);
ps = con.prepareStatement("update test_radeox set content=? where id =?");
StringBuffer content= new StringBuffer("CORE JAVA Question: What is a compilation unit? Question: What restrictions are placed on method overriding? ")
.append(" Answer:: Overridden methods must have the same name, argument list, and return type. ")
.append(" The overriding method may not limit the access of the method it overrides. ");
// ps.setAsciiStream(1,new ByteArrayInputStream(content.toString().getBytes()) ,content.length());
oracle.sql.CLOB newClob = oracle.sql.CLOB.createTemporary(con, false, oracle.sql.CLOB.DURATION_CALL);
newClob.putString(1,content.toString());
ps.setClob(1,newClob);
ps.setInt(2,1);
ps.executeUpdate();
System.out.println("insertded");*/
}
catch(Exception e){
e.printStackTrace();
}
finally{
try {
// con1.close();
con.close();
System.out.println("===connection===" +con.isClosed());
System.out.println("===prepareStatement===" +ps);
// ps.close();
System.out.println("===rs===" +rs);
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
2 comments:
Why have you disclosed your company IP , users and Password? Did you do a copy paste in Hurry?
Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Smartphone, I hope you enjoy. The address is http://smartphone-brasil.blogspot.com. A hug.
Post a Comment