string query question in java class

Hi experts, I've this code in my DAO:

public ArrayList getSearchResult(String strLegalEnt, String strExistingAccountType, String strOrgTypeCd, String strBranch){
                  getConnection();
                  String strQuery1 = "";
                  PreparedStatement pstmt = conn.prepareStatement(strQuery1);
                  pstmt.setString(1,strLegalEnt);
}

I want to use this sql query:

 SELECT LE.CUSTOMER_NAME LEGAL_ENTITY, LE.LEGAL_ENTITY_ID ACCOUNT_NUM, COUN.COUNTRY_DESCRIPTION COUN_NAME,

CURR.CURRENCY_NAME CURR_NAME, LE.GFCID_TYPE ORG_TYPE, BRAN.BRANCH_NAME

 FROM ECIF_DAM_LEGAL_ENTITY LE, ECIF_DAM_CUSTOMER CUST, ECIF_BANK_BRANCH BRAN, ECIF_COUNTRY COUN, ECIF_CURRENCY CURR

 WHERE LE.LEGAL_ENTITY_ID = CUST.LEGAL_ENTITY_ID AND LE.COUNTRY = COUN.COUNTRY_CODE AND COUN.CCY_CODE =

CURR.CCY_CODE AND CUST.BRANCH_ID = BRAN.BRANCH_ID

 AND LE.CUSTOMER_NAME LIKE '%';

how do i implement this query in that code??
thanks
KirtipurItagolAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
try:

String strQuery1 = "SELECT LE.CUSTOMER_NAME LEGAL_ENTITY, LE.LEGAL_ENTITY_ID ACCOUNT_NUM, COUN.COUNTRY_DESCRIPTION COUN_NAME,

CURR.CURRENCY_NAME CURR_NAME, LE.GFCID_TYPE ORG_TYPE, BRAN.BRANCH_NAME

 FROM ECIF_DAM_LEGAL_ENTITY LE, ECIF_DAM_CUSTOMER CUST, ECIF_BANK_BRANCH BRAN, ECIF_COUNTRY COUN, ECIF_CURRENCY CURR

 WHERE LE.LEGAL_ENTITY_ID = CUST.LEGAL_ENTITY_ID AND LE.COUNTRY = COUN.COUNTRY_CODE AND COUN.CCY_CODE =

CURR.CCY_CODE AND CUST.BRANCH_ID = BRAN.BRANCH_ID

 AND LE.CUSTOMER_NAME LIKE ?";
               PreparedStatement pstmt = conn.prepareStatement(strQuery1);
               pstmt.setString(1,"%"+strLegalEnt+"%");
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KirtipurItagolAuthor Commented:
customer_name corresponds to customer name field in the jsp and that's the required field. I want it to display the results even though the user types a single letter . So which one do you think is good to go, '%'or '?'
0
objectsCommented:
%
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

el_diosCommented:
Hi KirtipurItagol,
use this :
strQuery = "<your sql query which you specified>";
What I understood here is that strLegalEnt is the customer_name. Use a ? in its place.
 AND LE.CUSTOMER_NAME LIKE ?
the statement pstmt.setString(1,strLegalEnt); will replace the ? with the appropriate value. Say you give pstmt.setString(1,"%"); then it will be executed as " AND LE.CUSTOMER_NAME LIKE '%'". I have explained in much simplified terms here.

If you cant follow I'll put the code.

Cheers!
0
el_diosCommented:
sorry i didn't see the earlier posts
0
NelliosCommented:
You dont need to use a prepared Statement for this type of query, all you need is this

String sql+"select * from mytable";
ResultSet rs = connection.executeQuery(sql);
0
Mayank SAssociate Director - Product EngineeringCommented:
It is however recommended to use a PreparedStatement.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.