Enlightensoft's Blog

Helping in your each step

  • Categories

  • Authors

Read property value in Java file using sprng 3 annotation

Posted by Pankil Patel on May 6, 2013

Step 1: Add your property bean definition in applicationContext.xml:

<bean id=“myPropValue”     class=“org.springframework.beans.factory.config.PropertiesFactoryBean”>
               <property name=“location”value=“classpath:myPropertyFile.properties” />
</bean>
 

Step 2: Read Property by constructor injection of property bean into Spring service.:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 

@Service(“myService”)

public class MyServiceImpl implements MyService {

private Properties allValueProperties;

       @Autowired
       public MyServiceImpl (Properties myPropValue) {
              this.allValueProperties = myPropValue;
       }
       @Override
       public void springWebMethod() throws Exception {
                   String valueFromProperty = this.allValueProperties.getProperty(“enlighten.my.default.value.url”);
       }

}

Note: If you don’t want to inject property bean in to your each spring service bean where it is required, alternatively you can inject it into one common bean and create static map from it or create enum from that properties and use that static map or enum in your any class of your application.

Posted in Spring | Tagged: , , , , , , | Leave a Comment »

Maven error reading, error in opening zip file

Posted by Pankil Patel on January 15, 2013

error: error reading C:\Users\ppatel4\.m2\repository\org\apache\xalan\xalan\2.7.
1\xalan-2.7.1.jar; error in opening zip file

Step 1: Manually download xalan-2.7.1.jar

Step 2: Remove all files of: ~/.m2/repository/org/apache/xalan/xalan/2.7.1/

Step3: Copy the jar which is manually downloaded into the location: ~/.m2/repository/org/apache/xalan/xalan/2.7.1/

$ cp xalan-2.7.1.jar ~/.m2/repository/org/apache/xalan/xalan/2.7.1/

Its Done… Try to execute your mvn clean install command.

All the best…

Posted in Maven | Tagged: , , | Leave a Comment »

How to setup GMAIL account in BT-7722

Posted by Pankil Patel on January 2, 2013

VERY FIRST ENABLE POP3 FROM YOUR GMAIL ACCOUNT SETTINGS (thru internet browser). LOG IN TO YOUR GMAIL ACCOUNT > ON TOP RIGHT CLICK ON SETTINGS >THEN CLICK FORWARDING & POP3 > THEN ENABLE POP3 FOR ALL MAIL OR YOU CAN SELECT OTHER OPTION. BUT AT LEAST POP3 MUST BE ENABLED. THEN SAVE CHANGES.

POP3 Gmail Settings For Samsung B7722 / might be other samsung Cellphones also:

Go To > Menu (can be differ model to model basis but basic settings might be same for all samsung models > Messages

Click Settings > Email

Then Touch >Email Account / Email Setup Wizard

Then Touch > Add or Creat Account

Give name to your account name E.g Gmail or your Name or whatever you want

please note next menu orientation might be differ depending on model type, but you will find it)

SMTP / Outgoing Server : smtp.gmail.com

SMTP Port : 465

Secure Connection : SSL

Incoming Server type : POP3

POP3 / Incoming Server : pop.gmail.com

POP3 Port: 995

APOP Login : Tick

Secure Connection : SSL

Download Limit: 500

Retrieving Option: Choose Subject only (I have not tried for other option, you may try)

Keep On Server: Tick

My Email Address: type your gmail (email address)

Username /Password : your gmail ID / Password

POP before SMTP : Dont Tick

SMTP Auth: Tick

Same as POP3/IMAP4 : Tick

And Finally SAVE All Settings.

That’s it !!!, Now you can SEND & RECIEVE YOUR gmail messages on your samsung phones.

Best Of Luck……………………

Posted in Out Of The World | Leave a Comment »

Pass String (or Custom Object) List into Store Procedure from Java

Posted by Pankil Patel on November 1, 2012

  1. Create type:create or replace
    TYPE STRING_LIST_TYPE AS TABLE OF VARCHAR2(7);
  2. Java Code:ARRAY sqlArrayOfString = getSqlArray(arrayListOfString.toArray(), “STRING_LIST_TYPE”,
    tssPortalDataSource);
  3. Store Procedure input param:P_NAME in STRING_LIST_TYPE,
  4. Use list into IN parameter of query in Store Procedure:

select * from EMPLOY where EMPLOY_NAME in (select column_value from (Table(CAST(P_NAME AS STRING_LIST_TYPE))))

Posted in Core Java, Database, Oracle | Tagged: , | Leave a Comment »

Aggregate functions with extra column in select

Posted by Pankil Patel on October 31, 2012

How to select extra column(s) with aggregate function in query?

  1. Rollback script:
    ALTER TABLE EMP_DEPARTMENT DROP CONSTRAINT UNIQUE_1;
    DROP TABLE EMP_DEPARTMENT;
    DROP TABLE EMPLOY;
    DROP TABLE DEPARTMENT;
  2. Create script:
    CREATE TABLE “TSSRISKAPPDBO”.”EMPLOY”
    (
    “EMPLOY_ID”   NUMBER(10,0),
    “EMPLOY_NAME” VARCHAR2(100 BYTE),
    “SALARY”      NUMBER(10,2),
    CONSTRAINT “PK_EMPLOY” PRIMARY KEY (“EMPLOY_ID”) USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS TABLESPACE “AMRISKWLADBO_DATA” ENABLE
    )
    SEGMENT CREATION DEFERRED PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING TABLESPACE “AMRISKWLADBO_DATA” ;

    CREATE TABLE “TSSRISKAPPDBO”.”DEPARTMENT”
    (
    “DEPARTMENT_ID”   NUMBER(10,0),
    “DEPARTMENT_NAME” VARCHAR2(100 BYTE),
    CONSTRAINT “PK_DEPARTMENT” PRIMARY KEY (“DEPARTMENT_ID”) USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS TABLESPACE “AMRISKWLADBO_DATA” ENABLE
    )
    SEGMENT CREATION DEFERRED PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING TABLESPACE “AMRISKWLADBO_DATA” ;

    CREATE TABLE “TSSRISKAPPDBO”.”EMP_DEPARTMENT”
    (
    “EMPLOY_ID”     NUMBER(10,0),
    “DEPARTMENT_ID” NUMBER(10,0),
    CONSTRAINT “UNIQUE_1″ UNIQUE (“EMPLOY_ID”, “DEPARTMENT_ID”) USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS TABLESPACE “AMRISKWLADBO_DATA” ENABLE,
    CONSTRAINT “FK_EMP” FOREIGN KEY (“EMPLOY_ID”) REFERENCES “TSSRISKAPPDBO”.”EMPLOY” (“EMPLOY_ID”) ENABLE,
    CONSTRAINT “FK_DEPT” FOREIGN KEY (“DEPARTMENT_ID”) REFERENCES “TSSRISKAPPDBO”.”DEPARTMENT” (“DEPARTMENT_ID”) ENABLE
    )
    SEGMENT CREATION DEFERRED PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING TABLESPACE “AMRISKWLADBO_DATA” ;

  3. Data creation:
    INSERT INTO EMPLOY VALUES (1,’VIBHA’,21);
    INSERT INTO EMPLOY VALUES (2,’PANKIL’,10.2);
    INSERT INTO EMPLOY VALUES (3,’MAYANK’,15);
    INSERT INTO EMPLOY VALUES (4,’NAMRATA’,12);
    INSERT INTO EMPLOY VALUES (5,’NISHA’,9);
    INSERT INTO EMPLOY VALUES (6,’SHAILESH’,12);

    INSERT INTO DEPARTMENT VALUES (1,’APPS’);
    INSERT INTO DEPARTMENT VALUES (2,’UET’);
    INSERT INTO DEPARTMENT VALUES (3,’PROCESS’);
    INSERT INTO DEPARTMENT VALUES (4,’BPO’);

    INSERT INTO EMP_DEPARTMENT VALUES (1,1);
    INSERT INTO EMP_DEPARTMENT VALUES (2,2);
    INSERT INTO EMP_DEPARTMENT VALUES (3,3);
    INSERT INTO EMP_DEPARTMENT VALUES (4,4);
    INSERT INTO EMP_DEPARTMENT VALUES (5,4);
    INSERT INTO EMP_DEPARTMENT VALUES (6,1);
    INSERT INTO EMP_DEPARTMENT VALUES (6,3);
    INSERT INTO EMP_DEPARTMENT VALUES (4,1);
    INSERT INTO EMP_DEPARTMENT VALUES (4,2);
    INSERT INTO EMP_DEPARTMENT VALUES (6,2);

  4. Query: Get Employee(s) data of employee(s) who has the highest Salary in “BPO” department

    SELECT *
    FROM EMPLOY E,
    (SELECT MAX(SALARY) AS MAX_SALARY
    FROM EMPLOY
    WHERE EMPLOY_ID IN
    (SELECT EMPLOY_ID
    FROM EMP_DEPARTMENT
    WHERE DEPARTMENT_ID =
    (SELECT DEPARTMENT_ID FROM DEPARTMENT WHERE DEPARTMENT_NAME = ‘BPO’
    )
    )
    ) MAX_RESULT
    WHERE MAX_RESULT.MAX_SALARY = E.SALARY
    AND E.EMPLOY_ID            IN
    (SELECT EMPLOY_ID
    FROM EMP_DEPARTMENT
    WHERE DEPARTMENT_ID =
    (SELECT DEPARTMENT_ID FROM DEPARTMENT WHERE DEPARTMENT_NAME = ‘BPO’
    )
    );

 

Note: Summary of above code is: get inner join of any aggregate function’s result with the table field

Apply where condition at both places (In inner query having aggregate function  and In outer query with table)

Posted in Database, Oracle | 2 Comments »

“printf” in Oracle SQL Procedure

Posted by Pankil Patel on October 31, 2012

How you would print data to DBMS OUTPUT. during execution of Store Procedure?

OR

How to debug Oracle Store Procedure?

Below is the syntax to print data to DBMS OUTPUT:

DBMS_OUTPUT.PUT_LINE (‘PANKIL—————:’ || v_sql || ‘:’);

Posted in Database, Oracle | Tagged: , , , | Leave a Comment »

How to find dependent tables on my table?

Posted by Pankil Patel on October 3, 2012

Based on constraints on my table, how to find dependent tables?

Below is the query which will give me the tables name & constraint name those are related to MY_TABLE:

select table_name, constraint_name, status, owner
from all_constraints
where  r_constraint_name in
 (
   select CONSTRAINT_NAME from ALL_CONSTRAINTS
   WHERE upper(table_name) = ‘MY_TABLE’   
 )
order by table_name, constraint_name;

Posted in Database, Oracle | Tagged: , , , , , , | Leave a Comment »

How to Reload Applet or Remove class file Caching for Applet

Posted by Pankil Patel on August 26, 2012

Step1: Add below script to your HTML page after End of Body (After </BODY> tag)

<script type=”text/javascript”>
window.APPLET_WRAPER_TAG = “object”;
//window.APPLET_WRAPER_TAG = “APPLET”;
//window.APPLET_WRAPER_TAG = “EMBED”;

window.TAG_TYPE = “application/x-java-applet”;

window.currectApplet = true;
window.allAppletsHTML = new Array();
window.allApplets = new Array();

reloadApplet();

function reloadApplet() {

var resultListObects = getallAppletsHTML();

if (window.currectApplet) {
for (i = 0; i < resultListObects.length; i++) {
window.allAppletsHTML[i] = resultListObects[i].outerHTML;
var htmls = resultListObects[i].outerHTML.split(‘.class’);
htmls[0] = htmls[0] + ‘.class?PankilPatel’;
var html = htmls[0] + htmls[1];
resultListObects[i].outerHTML = html;
}
window.currectApplet = false;
} else {
for (i = 0; i < resultListObects.length; i++) {
resultListObects[i].outerHTML = window.allAppletsHTML[i];
}
window.currectApplet = true;
}
if (!window.currectApplet) {
reloadApplet(resultListObects);
}
}

function getallAppletsHTML() {
var listObects = document
.getElementsByTagName(window.APPLET_WRAPER_TAG);
var resultListObects = new Array();
for (i = 0, index = 0; i < listObects.length; i++) {
if (window.APPLET_WRAPER_TAG.toUpperCase() == “APPLET”
|| listObects[i].type == window.TAG_TYPE) {
resultListObects[index] = listObects[i];
index++;
}
}
return resultListObects;
}
</script>

 

Step2: Configure value of TAG which is used to display Applet in HTML Page, like object, APPLET or EMBED into first line of script.

Step3: Same way change value of “window.TAG_TYPE” to type given in TAG which is used to display applet, into second line of script.

 

Now no need to restart your any browser after applet change.

Enjoy your hassle free development of Applet……………….. :-)

 

Note: It will work only if you have used only one way to import applet into your HTML file which is any one of  object, APPLET or EMBED.

Posted in Applet | Tagged: , , , , , , | Leave a Comment »

Override toString to Display all class content (Except Static) Using Apache APIs

Posted by Pankil Patel on August 9, 2012

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this,
ToStringStyle.MULTI_LINE_STYLE);
}

Posted in Core Java | Tagged: , , , , , | Leave a Comment »

Export to .pdf using Core JAVA

Posted by Pankil Patel on June 22, 2012

Required JAR:

itextpdf-5.3.0.jar

itext-xtra-5.3.0.jar

 

 

File: PDFCreator.java

package co.cc.enlightensoft.pdf;

import java.io.FileOutputStream;

import com.itextpdf.text.Anchor;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

public class PDFCreator {
public static void main(String[] args) {
try {

// creation of the document with a certain size and certain margins
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try {
// creation of the different writers
// HtmlWriter.getInstance(document, System.out);
PdfWriter.getInstance(document,
new FileOutputStream(“text.pdf”));
// we add some meta information to the document
document.addAuthor(“Bruno Lowagie”);
document.addSubject(“This is the result of a Test.”);
// we open the document for writing
document.open();

// ##################### Paragraph : Start #####################
document.add(new Paragraph(“Hello world”));
// ##################### Paragraph : End #####################

// ##################### Chunk : Start #####################
Chunk chunk = new Chunk(“Hello world”, FontFactory.getFont(
FontFactory.COURIER, 20, Font.ITALIC, new BaseColor(
255, 0, 0)));
document.add(chunk);
// ##################### Chunk : End #####################

// ##################### Anchor : Start #####################
Anchor anchor = new Anchor(“\nGoogle\n”);
anchor.setName(“Google”);
anchor.setReference(“http://www.google.com&#8221;);

document.add(anchor);
// ##################### Anchor : End #####################

// ##################### Image : Start #####################
Image image = Image.getInstance(“Photo.JPG”);
image.scaleAbsolute(100, 100);
document.add(image);
// ##################### Image : End #####################

// ##################### Table : Start #####################
PdfPTable table = createTable1();
table.setSpacingBefore(5);
table.setSpacingAfter(5);
document.add(table);

// ##################### Table : End #####################

System.out.println(“File Created…”);
} catch (DocumentException de) {
System.err.println(de.getMessage());
}
document.close();
} catch (Throwable t) {
t.printStackTrace();
}
}

/** The resulting PDF file. */
public static final String RESULT = “text.pdf”;

/**
* Creates a table; widths are set with setWidths().
*
* @return a PdfPTable
* @throws DocumentException
*/
public static PdfPTable createTable1() throws DocumentException {
PdfPTable table = new PdfPTable(3);
table.setWidthPercentage(288 / 5.23f);
table.setWidths(new int[] { 2, 1, 1 });
PdfPCell cell;
cell = new PdfPCell(new Phrase(“Table 1″));
cell.setColspan(3);
table.addCell(cell);
cell = new PdfPCell(new Phrase(“Cell with rowspan 2″));
cell.setRowspan(2);
table.addCell(cell);
table.addCell(“row 1; cell 1″);
table.addCell(“row 1; cell 2″);
table.addCell(“row 2; cell 1″);
table.addCell(“row 2; cell 2″);
return table;
}

/**
* Creates a table; widths are set with setWidths().
*
* @return a PdfPTable
* @throws DocumentException
*/
public static PdfPTable createTable2() throws DocumentException {
PdfPTable table = new PdfPTable(3);
table.setTotalWidth(288);
table.setLockedWidth(true);
table.setWidths(new float[] { 2, 1, 1 });
PdfPCell cell;
cell = new PdfPCell(new Phrase(“Table 2″));
cell.setColspan(3);
table.addCell(cell);
cell = new PdfPCell(new Phrase(“Cell with rowspan 2″));
cell.setRowspan(2);
table.addCell(cell);
table.addCell(“row 1; cell 1″);
table.addCell(“row 1; cell 2″);
table.addCell(“row 2; cell 1″);
table.addCell(“row 2; cell 2″);
return table;
}

/**
* Creates a table; widths are set in the constructor.
*
* @return a PdfPTable
* @throws DocumentException
*/
public static PdfPTable createTable3() throws DocumentException {
PdfPTable table = new PdfPTable(new float[] { 2, 1, 1 });
table.setWidthPercentage(55.067f);
PdfPCell cell;
cell = new PdfPCell(new Phrase(“Table 3″));
cell.setColspan(3);
table.addCell(cell);
cell = new PdfPCell(new Phrase(“Cell with rowspan 2″));
cell.setRowspan(2);
table.addCell(cell);
table.addCell(“row 1; cell 1″);
table.addCell(“row 1; cell 2″);
table.addCell(“row 2; cell 1″);
table.addCell(“row 2; cell 2″);
return table;
}

/**
* Creates a table; widths are set with special setWidthPercentage() method.
*
* @return a PdfPTable
* @throws DocumentException
*/
public static PdfPTable createTable4() throws DocumentException {
PdfPTable table = new PdfPTable(3);
Rectangle rect = new Rectangle(523, 770);
table.setWidthPercentage(new float[] { 144, 72, 72 }, rect);
PdfPCell cell;
cell = new PdfPCell(new Phrase(“Table 4″));
cell.setColspan(3);
table.addCell(cell);
cell = new PdfPCell(new Phrase(“Cell with rowspan 2″));
cell.setRowspan(2);
table.addCell(cell);
table.addCell(“row 1; cell 1″);
table.addCell(“row 1; cell 2″);
table.addCell(“row 2; cell 1″);
table.addCell(“row 2; cell 2″);
return table;
}

/**
* Creates a table; widths are set with setTotalWidth().
*
* @return a PdfPTable
* @throws DocumentException
*/
public static PdfPTable createTable5() throws DocumentException {
PdfPTable table = new PdfPTable(3);
table.setTotalWidth(new float[] { 144, 72, 72 });
table.setLockedWidth(true);
PdfPCell cell;
cell = new PdfPCell(new Phrase(“Table 5″));
cell.setColspan(3);
table.addCell(cell);
cell = new PdfPCell(new Phrase(“Cell with rowspan 2″));
cell.setRowspan(2);
table.addCell(cell);
table.addCell(“row 1; cell 1″);
table.addCell(“row 1; cell 2″);
table.addCell(“row 2; cell 1″);
table.addCell(“row 2; cell 2″);
return table;
}

}

Posted in Core Java | Tagged: , , , , , , , | 1 Comment »

 
Follow

Get every new post delivered to your Inbox.