Tuesday, October 29, 2013

writePDFToResponse

 private void writePDFToResponse(HttpServletResponse response, PdfPTable pdfTable, PdfPTable resTable, String fileName) throws IOException, DocumentException {
        Document document = new Document(PageSize.A4.rotate());
        document.setPageSize(PageSize.A4);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);
        document.open();
        document.add(pdfTable);
        document.add(resTable);
        document.close();

        response.setCharacterEncoding("UTF-8");
        String content = new String("application/pdf".getBytes(),"UTF-8");
        response.setContentType(content);
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "public");
        response.setHeader("Content-disposition", "attachment;filename="+ fileName + ".pdf");
        response.setContentLength(baos.size());

        System.out.print(response.getCharacterEncoding());

        ServletOutputStream out = response.getOutputStream();
        baos.writeTo(out);
        out.flush();
    }

Monday, October 28, 2013

sms api


      Date st= new Date();
       URL myURL = new URL("http://www.resalty.net/api/sendSMS.php?userid=YYYYYYY&password=XXXXXXXX&sender=XXX&to=966530XXXX&msg=Test"+st.toString());
    URLConnection myURLConnection = myURL.openConnection();
    myURLConnection.connect();
    myURLConnection.getContent();

Tuesday, August 27, 2013

java.util.ConcurrentModificationException

 for(DbtDebtVchrSum com:this.companySummary)
        {
            if(com.getTotalDebit().compareTo(com.getPayment())==0)
              rmvList.add(com);
        }
       
       
        for(DbtDebtVchrSum com:rmvList)
        {
            this.companySummary.remove(com);
        }

Tuesday, August 13, 2013

JPA Custom Query

    Query q1 = em.createQuery("SELECT e.name, e.salary FROM Employee e");
    List<Object[]> result1 = q1.getResultList();
    for (Object[] resultElement : result1) {
        String name = (String)resultElement[0];
        Double salary = (Double)resultElement[1];
        ...
    }

    Query q2 = em.createQuery("SELECT e.name, e.salary, e.department FROM Employee e");
    List<Object[]> result2 = q2.getResultList();
    for (Object[] resultElement : result2) {
        String name = (String)resultElement[0];
        Double salary = (Double)resultElement[1];
        Department dept = (Department)resultElement[2];
        ...
    }

    Query q3 = em.createQuery("SELECT COUNT(e), SUM(e.salary) FROM Employee e");
    Object[] result3 = (Object[])q3.getSingleResult();
    Long count = (Long)result3[0];
    Double sum = (Double)result3[1];

Tuesday, June 18, 2013

Oracle Flash Back Query

SELECT *
FROM TABLE
AS OF TIMESTAMP TO_TIMESTAMP('18-JUN-13 10.00.00.000000')

Wednesday, April 10, 2013

Oracle JDBC Mapping

SQL and PL/SQL Data TypeOracle MappingJDBC Mapping
CHARCHARACTERLONGSTRINGVARCHARVARCHAR2
oracle.sql.CHAR
java.lang.String
NCHARNVARCHAR2
oracle.sql.NCHAR (note 1)
oracle.sql.NString (note 1)
NCLOB
oracle.sql.NCLOB (note 1)
oracle.sql.NCLOB (note 1)
RAWLONG RAW
oracle.sql.RAW
byte[]
BINARY_INTEGERNATURALNATURALNPLS_INTEGERPOSITIVEPOSITIVEN,SIGNTYPEINTINTEGER
oracle.sql.NUMBER
int
DECDECIMALNUMBERNUMERIC
oracle.sql.NUMBER
java.math.BigDecimal
DOUBLE PRECISIONFLOAT
oracle.sql.NUMBER
double
SMALLINT
oracle.sql.NUMBER
int
REAL
oracle.sql.NUMBER
float
DATE
oracle.sql.DATE
java.sql.Timestamp
TIMESTAMP
TIMESTAMP WITH TZ
TIMESTAMP WITH LOCAL TZ
oracle.sql.TIMESTAMP
oracle.sql.TIMESTAMPTZ
oracle.sql.TIMESTAMPLTZ
java.sql.Timestamp
INTERVAL YEAR TO MONTH
INTERVAL DAY TO SECOND
String (note 2)
String (note 2)
ROWIDUROWID
oracle.sql.ROWID
oracle.sql.ROWID
BOOLEAN
boolean (note 3)
boolean (note 3)
CLOB
oracle.sql.CLOB
java.sql.Clob
BLOB
oracle.sql.BLOB
java.sql.Blob
BFILE
oracle.sql.BFILE
oracle.sql.BFILE
Object types
Generated class
Generated class
SQLJ object types
Java class defined at type creation
Java class defined at type creation
OPAQUE types
Generated or predefined class (note 4)
Generated or predefined class (note 4)
RECORD types
Through mapping to SQL object type (note 5)
Through mapping to SQL object type (note 5)
Nested table, VARRAY
Generated class implemented usingoracle.sql.ARRAY
java.sql.Array
Reference to object type
Generated class implemented usingoracle.sql.REF
java.sql.Ref
REF CURSOR
java.sql.ResultSet
java.sql.ResultSet
Index-by tables
Through mapping to SQL collection (note 6)
Through mapping to SQL collection (note 6)
Scalar (numeric or character)
Index-by tables
Through mapping to Java array (note 7)
Through mapping to Java array (note 7)

Monday, January 28, 2013

Tomcat as Windows service


 service.bat install <service_name>

Tuesday, January 22, 2013

XML submit


HttpPost httppost = new HttpPost(SERVICE_EPR);          
StringEntity se = new StringEntity(SOAPRequestXML,HTTP.UTF_8);

se.setContentType("text/xml");  
httppost.setHeader("Content-Type","application/soap+xml;charset=UTF-8");
httppost.setEntity(se);  

HttpClient httpclient = new DefaultHttpClient();
BasicHttpResponse httpResponse = 
    (BasicHttpResponse) httpclient.execute(httppost);

response.put("HTTPStatus",httpResponse.getStatusLine().toString());

Monday, January 07, 2013

Generate CSR File glassfish /Java


keytool -keysize XXXXX -genkey -alias XXXXXX -keyalg XXX  -keystore keystore.jks -keypass XXXXX -storepass XXXXX
keytool -certreq -alias XXXXXX -keystore keystore.jks -storepass XXXX -keypass XXXX -file server.csr