im new to java so if im doing some thing the wrong way please let me know
this is the class that connects to data base and grabs all the info from colum 1
and colum 2 that part works

now when i try to either make it a useable list either by making it a vector or arraylist it gives me a error because coloum two is all data not just numbers any help is appreciated


this is the part of my code that works i took out the other stuff

import java.util.*;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class connector {
    
    public static void main(String[] args) {

        Connection con = null;
        PreparedStatement pst = null;
        ResultSet rs = null;

        String url = "****";
        String user = "****";
        String password = ****";

   

        try {
            
            con = DriverManager.getConnection(url, user, password);
            pst = con.prepareStatement("SELECT * FROM `custom`");
            rs = pst.executeQuery();
            
            while (rs.next()) {
            	 
                System.out.print(rs.getInt(1));

            }

         

        } catch (SQLException ex) {
                Logger lgr = Logger.getLogger(connector.class.getName());
                lgr.log(Level.SEVERE, ex.getMessage(), ex);

        } finally {

            try {
                if (rs != null) {
                    rs.close();
                }
                if (pst != null) {
                    pst.close();
                }
                if (con != null) {
                    con.close();
                }

            } catch (SQLException ex) {
                Logger lgr = Logger.getLogger(connector.class.getName());
                lgr.log(Level.WARNING, ex.getMessage(), ex);
            }
        }
    }
}

Edited 5 Years Ago by HITMANOF44th: n/a

hi HITMANOF44th,
First you separate your main class and your connection class

classes are not tested
// your main class

DataManager dataManager = new DataManager();

dataManager.setDbURL(dbURL);
dataManager.setDbUserName(dbUserName);
dataManager.setDbPassword(dbPassword);
dataManager.setjdbcDriver(jdbcDriver);
.
.
.
dataManager.getConnection();
Retrieve retrieve =new Retrieve ();
ArrayList<UserBean> list;
list =new ArrayList<UserBean>(dataManager.getUserData(the values you want to pass query );
for(int i=0;i < list.size(); i++) {
system.out.println(list.get(i));
}

// Datamanager class

public Retrieve getUserData(String str_userid, String str_pass) {
			
	    	Retrieve retrieve =new Retrieve ();
			
	    	try{
	    		query ="sql query  ";
	    		pstm = con.prepareStatement(query);
	    		pstm.setString(1,str_userid);
	    		pstm.setString(2,str_pass);	
	    		rs=pstm.executeQuery();
	    		if(rs.next()){
	    			retrieve.setUserid(rs.getString(***));
	    			retrieve .setPassword(rs.getString("***"));
				
					
	    		}
	    		
		}
		catch (SQLException e) {
			//e.printStackTrace();
			 System.out.println(e.getMessage());
			
			
		}
		
		return retrieve ;
	}

//Retrieve class

public void setUserid(String str) {userid = str;}
    public String getUserid() { return userid;}
    
    public void setPassword(String str) {password = str;}
    public String getPassword() { return password;}
This question has already been answered. Start a new discussion instead.