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

  • SEARCH
  • Home
  • 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 7071897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:44:35+00:00 2026-05-28T05:44:35+00:00

String query = select email from emp_select; Statement stmt; try { DB db=new DB();

  • 0
String query = "select email from emp_select";
Statement stmt;

try {

  DB db=new DB(); 
  db.connect();
  stmt = (Statement) db.conn.createStatement(); // DB is connected here              

  ResultSet rs = stmt.executeQuery(query);
  ResultSetMetaData rsmd = rs.getMetaData();

  int numberOfColumns = rsmd.getColumnCount();

  for (int i = 1; i <= numberOfColumns; i++) {
    if (i > 1)
        System.out.print(",  ");
  }
  System.out.println("");

  while (rs.next()) {
    for (int i = 1; i <= numberOfColumns; i++) {
        if (i > 1)
            System.out.print(",  ");

        String columnValue = rs.getString(i);
        name[i]=columnValue;
        System.out.println(name[i]);          //Everything executes well till here
    }
  }
  stmt.close();
} catch(Exception ex) {}

for (int i = 1; i < name.length; i++) {
    System.out.println(name[i]);   // why it gives null value here ?
}
  • 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-28T05:44:35+00:00Added an answer on May 28, 2026 at 5:44 am

    I was wondering is this what you really want :

    while (rs.next()) {
        for (int i = 1; i <= numberOfColumns; i++) {
            if (i > 1)
                System.out.print(",  ");
    
            String columnValue = rs.getString(i);
            name[i]=columnValue;
            System.out.println(name[i]);          //Everything executes well till here
        }
      }
    

    Here what is happening is , the while loop starts, now for loop begins execution, now inside the for loop you are giving all elements of name array the same value i.e. rs.getString(i), but your query returns only one column for your rs, i.e. email (but you coding in your for loop something like names[2] = rs.getString(2), name[3] = rs.getString(3), but here there is nothing other than rs.getString(1)). Seems like what you should do is this, that might can give you expected results

    for (int i = 1; i <= numberOfColumns; i++) {
            if (i > 1)
                System.out.print(",  ");
            if (rs.next()) // hope this works, not sure (but it does works for me at the click of a button, when used through Swing Events)
            {
                String columnValue = rs.getString(1);// Since only one thing is being returned by your rs object.
                name[i]=columnValue;
                System.out.println(name[i]);          //Everything executes well till here
            }
        }
    

    Hopefully this might can solve.

    Regards

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

Sidebar

Related Questions

Consider this: $email = 'c5dfd29d956b52c1ffa00ce4a06abad2'; // From the query string (MD5) $result = mysql_query('SELECT
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 some code like this : PersistenceManager pm=PMF.get().getPersistenceManager(); String query=select from +PayPal_Message.class.getName()+ where
I have this query. SELECT purchase_log.id, purchase_log.date_purchased, purchase_log.total_cost, purchase_log.payment_status, cart_contents.product_name, members.first_name, members.last_name, members.email FROM
I have a SqlDependency set up using the following query: string sql = "SELECT
if (isset($_POST['login'])) { $query = mysql_query(" SELECT id FROM users WHERE username = '".mysql_real_escape_string($_POST['username'])."'
I use query string to access my pages. I try to make if anyone
org.hibernate.hql.ast.QuerySyntaxException: users is not mapped [SELECT email, id FROM users WHERE email='dsdd@dds.com' AND password='asasas']

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.