[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

string query question in java class

Posted on 2006-04-12
7
Medium Priority
?
257 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:KirtipurItagol
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 16442268
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
 

Author Comment

by:KirtipurItagol
ID: 16442300
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
 
LVL 92

Expert Comment

by:objects
ID: 16442316
%
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:el_dios
ID: 16442564
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
 
LVL 3

Expert Comment

by:el_dios
ID: 16442576
sorry i didn't see the earlier posts
0
 
LVL 10

Expert Comment

by:Nellios
ID: 16444917
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 16451608
It is however recommended to use a PreparedStatement.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month20 days, 13 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question