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 8388325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:27:01+00:00 2026-06-09T18:27:01+00:00

Im am looking for a way to verify if the number the user entered

  • 0

Im am looking for a way to verify if the number the user entered corresponds with data stored in a database. Eg. If the user entered ‘5132’ it would load all the data from a specific column into a the array and then I would loop that data and compare the input to it in the hopes of finding a match.

Simply: How do I parse data from a database (resultset) into an int array?

A simple example of what Im trying to get at

String s = JOptionPane.showInputDialog(...);
int intS = Integer.parseInt(s);
boolean correct = false;

Get database info
count++; //for every data entry

int TagNumber [] = new int [count];

for (int i=0;i<count;i++) {
 if (intS == TagNumber[i]) {
  correct =true;
  break;
 }
}
  • 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-06-09T18:27:03+00:00Added an answer on June 9, 2026 at 6:27 pm

    If you really want to load the values from the database and check for a specific value from the user, then you could use a Binary search, otherwise you could use a SQL query as well.

    Below is an implementation (Binary Search) to find a value in an Array.

    public class BinarySearch {
    
        public static void main(String[] a) {
            int[] numArray = {5,6,10,11,19,18,30,25,88,44,55,1,3};
            Arrays.sort(numArray);
            // performing a binary search - here 100 is the element that you want 
                // to search in your array
            System.out.println(searchElement(numArray, 100));
        }
    
        private static int searchElement(int[] sortedArray, int element) {
    
            int first = 0;
            int upto  = sortedArray.length;
    
            while (first < upto) {
                int mid = (first + upto) / 2;  // Compute mid point.
                if (element < sortedArray[mid]) {
                    upto = mid;       // repeat search in bottom half.
                } else if (element > sortedArray[mid]) {
                    first = mid + 1;  // Repeat search in top half.
                } else {
                    return sortedArray[mid];       // Found it. You can return the position or the element
                }
            }
            return -1;    // The element is not in the array
        }
    }
    

    The database functionality

    public class RetrieveValues {
        public static void main(String args[]) throws SQLException {
            Connection conn = null;
            Statement select = null;
            try {
                Class.forName("com.somejdbcvendor.TheirJdbcDriver");
                conn = DriverManager.getConnection(
                                "jdbc:somejdbcvendor:other data needed by some jdbc vendor",
                                "myLogin", "myPassword");
                select = conn.createStatement();
                ResultSet result = select
                        .executeQuery("SELECT Element FROM TestTable");
    
                List<Integer> elementList = new ArrayList<Integer>();
                while (result.next()) { // process results one row at a time
                    elementList.add(result.getInt(1));
                }
                // convert to int array
    
                convertIntegers(elementList);
    
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } finally {
                select.close();
                conn.close();
            }
        }
    
        public static int[] convertIntegers(List<Integer> elemIntegers)
        {
            int[] elements = new int[elemIntegers.size()];
            for (int i=0; i < elements.length; i++)
            {
                elements[i] = elemIntegers.get(i).intValue();
            }
            return elements;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i was looking for a way to verify the domain with a provided
I am looking for a way to verify if my app was downloaded by
I'm looking for the right approach to verify a currently running executable from within
I'm looking for a way to sign some data in C++ code which will
I'm looking for a way to verify against an array. I'm lost in the
Possible Duplicate: Best way to detect when user leaves a web page I'm looking
Is there a way to run a user specified console application from an html
I'm looking for way to verify whether a site is categorized in any url
I am looking for a better way to verify that no field is left
What i'm trying to do is basically create one way to verify that all

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.