0

Hello I'm making an app in java!my program loads data from a database and we can make some changes (like deletion, import, etc.) through it. I'm at the point where I want to load the items into a JTable. I'm trying to get the type of the object but I get NullPointerException.

I'm sorry if I'm not understandable, it's just my first time I'm asking here.

    @Override
public Object getValueAt(int row,int col) {
    Object retVal=null;
    try{
        rs.absolute(row + 1);
        switch(col) {
            case 0:
                if(rs.getString(c1) == null){
                    retVal=String.valueOf(rs.getInt(c1));
                    break;
                }
                else{
                    retVal=rs.getString(c1);
                    break;
                }
            case 1:
                if(rs.getString(c2) == null){
                    retVal=String.valueOf(rs.getInt(c2));
                    break;
                }
                else{
                    retVal=rs.getString(c2);
                    break;
                }
            case 2:
                if(rs.getString(c3) == null){
                    retVal=String.valueOf(rs.getInt(c3));
                    break;
                }
                else{
                    retVal=rs.getString(c3);
                    break;
                }
            case 3:
                if(rs.getString(c4) == null){
                    retVal=String.valueOf(rs.getInt(c4));
                    break;
                }   
                else{
                    retVal=rs.getString(c4);
                    break;
                }

            case 4:
                if(rs.getString(c5) == null){
                    retVal=String.valueOf(rs.getInt(c5));  
                    break;
                }
                else{
                    retVal=rs.getString(c5);
                    break;
                }
            case 5:
                if(rs.getString(c6) == null){
                    retVal=String.valueOf(rs.getInt(c6));
                    break;
                }
                else{
                    retVal=rs.getString(c6);
                    break;
                }
        }           
    } catch(SQLException e) {
        System.out.println("getValueAt: " + e.getMessage());
    }
    return retVal;
}
  • Use the `ResultSetMetaData` available from the `ResultSet` – MadProgrammer Jun 05 '18 at 01:38
  • its good idea but if you see my code in `if else statement` the `c1 ,c2 ,c3 , etc` are strings containing collumns names (like "iduser","lastname", etc) if i use th `getColumnType` take int for parametres and returns sql type. – M. Koutoulakis Jun 05 '18 at 01:58

0 Answers0