Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5943125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:21:01+00:00 2026-05-22T16:21:01+00:00

String query=select dept_id,deptName from dept; PreparedStatement ps=cnn.prepareStatement(query); rs=ps.executeQuery(); while(rs.next()){ String st1 = rs.getString(1); String

  • 0
   String query="select dept_id,deptName from dept";
    PreparedStatement ps=cnn.prepareStatement(query);
    rs=ps.executeQuery();    
    while(rs.next()){           
    String st1 = rs.getString(1);
    String str2= rs.getString(2);
    }       
    ps.close();        

I made one method for each insert, update, delete queries that could be used around the project. In the same way I am trying to develop one select method that could get any query and return the results. I tried ArrayList to retriew the record and now its working but displaying records here there not in a sequence. The code is as follow:
public ArrayList selectQuery(
String columNames,String tableNames,
String whereClause,String whereValues)throws Exception{

ArrayList<ArrayList> resultList = new ArrayList<ArrayList>();        
    ArrayList<String> resultRecord = null;  

try{
    if ((cnn==null)||cnn.isClosed()){
    cnn=DB.getOracleConnection();
    }

    if(whereClause==null || whereClause.equals("")){
        whereClause="";
    }

    String query = "select "+columNames+" from "+tableNames+" "+whereClause;

            PreparedStatement ps=cnn.prepareStatement(query); 

            if(whereValues==null || whereValues.equals("")){
    //do nothing
    }
    else{
        int j=1;
        String[] words = whereValues.split (",");
        for (int i=0; i < words.length; i++){   
            words[i]=removeDot(whereValues);
            ps.setString(j, words[i]);
            j+=1;
        }
    }//whereValuesNullCheck

            rs=ps.executeQuery();     
            ResultSetMetaData rsmd = rs.getMetaData();     

            while(rs.next()){                           

        resultRecord= new ArrayList<String>(); 

                    for(int i=1;i<=rsmd.getColumnCount();i++){        
                    resultRecord .add(rs.getString(i));   
                    }        
                resultList.add(resultRecord); 
            }     
    ps.close();      

        } catch (Exception e) {   
System.out.println("ERROR: "+e.toString());
SendEmail.send(mail,"raakh5@gmail.com","Problem in ASC.DAOMethods.select()", "+e.printStackTrace()+"); 
        }     

return resultList;

}//methodClosed

and I am calling in the following method

public String viewPatients(ArrayList<ArrayList> result,String option)throws Exception{

PatientDAO pd = new PatientDAO();
DAOMethods dm = new DAOMethods();

String dataSet1="",dataSet2="",dataSet3="",records="",data="",country="",nationality="",source="",center="";

for(ArrayList record : result){

String patientId    =(String) record.get(0);
String rDate        =(String) record.get(1);
String title        =(String) record.get(2);
String firstName    =(String) record.get(3);
String lastName     =(String) record.get(4);
String country1     =(String) record.get(5);
String nationality1     =(String) record.get(6);
String source1      =(String) record.get(7);
String center1      =(String) record.get(8);

String title1 = cm.title(((String)title));
String name     = title1+" "+firstName+" "+lastName;

country         = c.displaySepecificCountry(((String)country1));
nationality         = c.displaySepecificCountry(((String)nationality1));
source          = cm.source(((String)source1));
String centerLocation   = pd.centerLocation(((String)center1));
center          = c.displaySepecificCountry(((String)centerLocation));
int age=9;

dataSet1+=
    "<tr "+cm.rowColor()+">"+
    "<td width=110  height=32 align=center class=normalFont>"+
    "<a href=/servlet/PatientManager?option=5&patientId="+patientId+">"+
    rDate+"</a></td>"+

    "<td width=110  align=center class=normalFont>"+
    "<a href=/servlet/PatientManager?option=5&patientId="+patientId+">"+
    "<font color=blue><b>"+patientId+"</b></font></a></td>";    

dataSet3+=
    "<td height=32 class=normalFont>"+
    "<a href=/servlet/PatientManager?option=5&patientId="+patientId+">"+
    name+"</a></td>"+

    "<td width=75 align=center class=normalFont>"+
    "<a href=/servlet/PatientManager?option=5&patientId="+patientId+"><font color=blue><b>"+
    age+"</b></font></a></td>"+

    "<td width=140 align=center class=normalFont>"+
    "<a href=/servlet/PatientManager?option=5&patientId="+patientId+">"+country+"</a></td>"+

    "<td width=75  align=center class=normalFont>"+
    "<a href=/servlet/PatientManager?option=5&patientId="+patientId+">"+nationality+"</a></td>"+    

    "<td width=75  align=center class=normalFont>"+
    "<a href=/servlet/PatientManager?option=5&patientId="+patientId+">"+source+"</td>"+

    "<td width=45>"+
    "<a href=/servlet/PatientManager?option=6&patientId="+patientId+">"+
    "<img src=/images/edit1.png border=0></a></td>"+
    "</tr>";
}
records=dataSet1+dataSet2+dataSet3;

return records;
}

Its working with the results fine but displaying records here there like on this link: http://www.onlinenics.com/images/error.jpg

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:21:02+00:00Added an answer on May 22, 2026 at 4:21 pm

    If the comments above are correct in speculating that different result sets get different numbers of columns back, you have to be able to tell which columns have values. Use the names of the columns to get the values. Use an empty string where you have none.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

String query = SELECT COUNT(*) AS count FROM table1; ResultSet rs = DBConnection.executeQuery(query); The
I make a query: String query = SELECT DISTINCT a FROM A a FETCH
I am building an ObjectQuery like this: string query = select value obj from
My query string is like: SELECT ... FROM maintable LEFT JOIN table1 on (maintable.id
I have the following Java code: String query = Select 1 from myTable where
I have this example code: string query = select * from xy where id
private void BindPrimaryGrid() { string constr = ConfigurationManager.ConnectionStrings[conString].ConnectionString; string query = select * from
I want select multiple (all) values from table Account. string query = SELECT *
string query = select * from cfo_daily_trans_hist; try { using (SqlConnection connection = new
I have that code : string query = select count(*) from MODEL m join

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.