We’re rewarding the question askers & reputations are being recalculated! Read more.
3 deleted 51 characters in body; edited title
source | link

Check input from user, works - but is there any better solution?

First of all, this code works on my project, but I think its not the most elegant solution. Have someone any improvements?

Aim: Read in the userID, check if the userID has 10-digits and check if it not exists in database, when both right, the program will leave the loop.  

This code works on my project, but I think its not the most elegant solution. Have someone any improvements?

InputReader.java

and here the second class:

Check input from user, works - but is there any better solution?

First of all, this code works on my project, but I think its not the most elegant solution. Have someone any improvements?

Aim: Read in the userID, check if the userID has 10-digits and check if it not exists in database, when both right, the program will leave the loop.  

InputReader.java

and here the second class:

Check input from user

Aim: Read in the userID, check if the userID has 10-digits and check if it not exists in database, when both right, the program will leave the loop.

This code works on my project, but I think its not the most elegant solution. Have someone any improvements?

InputReader.java

2 deleted 17 characters in body
source | link

First of all, this code works on my project, but I think its not the most elegant solution. Have someone anany improvements? Thanks in advance.

public class KundenInfoCustomerInfo {

    private Connection conn = null;
    private ResultSet resultSet = null;

    public CustomerInfo () {

        try {
                conn = null;
                JDBCConnection jdbcConn = new JDBCConnection(); 
                conn = jdbcConn.openConnection();             

        } catch (Exception e) {
                  throw e;
                } 
        };


        public int checkUserID (String userID) throws SQLException {
        PreparedStatement pstmt = null;
            String sql = "SELECT * FROM TABL0001 WHERE USERID = ?";     
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1,  userID);
            resultSet = pstmt.executeQuery();


            if (!resultSet.next()){
                return 0;

            }
               return 1;

        }

First of all, this code works on my project, but I think its not the most elegant solution. Have someone an improvements? Thanks in advance.

public class KundenInfo {

    private Connection conn = null;
    private ResultSet resultSet = null;

    public CustomerInfo () {

        try {
                conn = null;
                JDBCConnection jdbcConn = new JDBCConnection(); 
                conn = jdbcConn.openConnection();             

        } catch (Exception e) {
                  throw e;
                } 
        };


        public int checkUserID (String userID) throws SQLException {
        PreparedStatement pstmt = null;
            String sql = "SELECT * FROM TABL0001 WHERE USERID = ?";     
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1,  userID);
            resultSet = pstmt.executeQuery();


            if (!resultSet.next()){
                return 0;

            }
               return 1;

        }

First of all, this code works on my project, but I think its not the most elegant solution. Have someone any improvements?

public class CustomerInfo {

    private Connection conn = null;
    private ResultSet resultSet = null;

    public CustomerInfo () {

        try {
                conn = null;
                JDBCConnection jdbcConn = new JDBCConnection(); 
                conn = jdbcConn.openConnection();             

        } catch (Exception e) {
                  throw e;
                } 
        };


        public int checkUserID (String userID) throws SQLException {
        PreparedStatement pstmt = null;
            String sql = "SELECT * FROM TABL0001 WHERE USERID = ?";     
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1,  userID);
            resultSet = pstmt.executeQuery();


            if (!resultSet.next()){
                return 0;

            }
               return 1;

        }
1
source | link

Check input from user, works - but is there any better solution?

First of all, this code works on my project, but I think its not the most elegant solution. Have someone an improvements? Thanks in advance.

Aim: Read in the userID, check if the userID has 10-digits and check if it not exists in database, when both right, the program will leave the loop.

InputReader.java

public class InputReader {

    private String userID;


    public void readInput() throws SQLException {

        boolean UserIDExists = false;
        int existsValue = 0;

        try {

    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    System.out.println("UserID (10-digits):");


    while(!UserIDExists) {

        this.userID = input.readLine();

        while (this.userID.length() != 10) {


        System.out
                .println("Input must be 10 digits. Type again: :");
        this.userID = input.readLine();

        }

    CustomerInfo customer = new CustomerInfo();
    existsValue = customer.checkCustomer(this.userID);

    if (existsValue == 1) {

        UserIDExists = false; 
        System.out.println("UserID exists already. Type again:");   

    } else {

        UserIDExists = true;

    }   
    }

and here the second class:

CustomerInfo.java

public class KundenInfo {

    private Connection conn = null;
    private ResultSet resultSet = null;

    public CustomerInfo () {

        try {
                conn = null;
                JDBCConnection jdbcConn = new JDBCConnection(); 
                conn = jdbcConn.openConnection();             

        } catch (Exception e) {
                  throw e;
                } 
        };


        public int checkUserID (String userID) throws SQLException {
        PreparedStatement pstmt = null;
            String sql = "SELECT * FROM TABL0001 WHERE USERID = ?";     
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1,  userID);
            resultSet = pstmt.executeQuery();


            if (!resultSet.next()){
                return 0;

            }
               return 1;

        }