0

From Class Model:

    public TableModel getTableData() {
     TableModel model=null;
    try {
        String sql = "SELECT eventID as 'Event ID', date as 'Date',eventName as 'Name', time as 'Start Time' FROM Event";
        pst = conn.prepareStatement(sql); 
        rs = pst.executeQuery();
        model = (DbUtils.resultSetToTableModel(rs));       
        }
    catch(SQLException e){
        e.printStackTrace();
    }
   finally {
        try {rs.close(); pst.close();  }
        catch(SQLException e){}     }                                 
       return model; 
}

public void getEvent(String tableClick) {
    Events e = new Events();
    try {
        pst = conn.prepareStatement("SELECT * FROM Event WHERE eventID='"+tableClick+"' ");
        rs = pst.executeQuery();
        while(rs.next()){      
        e.setEventName(rs.getString(2));
        e.setEventDate(rs.getDate(3));
        e.setEventTime(rs.getString(4));
        e.setEventVenue(rs.getString(5));
        e.setEventDetail(rs.getString(6));
        e.setEventOpportunity(rs.getString(7));
        e.setEventMoreDetails(rs.getString(8));
        e.setEndTime(rs.getString(9));
       }
    } 
    catch(SQLException ex){
    ex.printStackTrace();
    } finally {
        try {
        rs.close();pst.close();conn.close();} 
        catch (Exception ex){}
      }
} //end getEvent

From Class Controller:

@Override
    public void valueChanged(ListSelectionEvent event) {
        int rowSelected = view.tableEvent.getSelectedRow();
        String tableClick = view.tableEvent.getModel().getValueAt(view.tableEvent.convertRowIndexToModel(rowSelected), 0).toString();
        model.getEvent(tableClick); //tell model to change its state based on user input on views - model is instance of class model
    } 

When I run my program I have stacktrace showing error at line pst = conn.prepareStatement("SELECT * FROM Event WHERE eventID='"+tableClick+"' "); of the Model Class, and line model.getEvent(tableClick); of the Controller class. Having run the programme with break points in debug mode in NetbeanIDE, I can see only the e.setEventName(...) being populated with a value from database, while all other values of the Event bean class are null. e.setEventDate(...) sets date as #2222. If you need further information I will edit my post. but this is really bugging me.

Is it the ListSelectionListener causing problem, perhaps mouseListener more appropriate?

to further add, if I change the getEvent() to

public void getEvent(String tableClick) {
Events e = new Events();
try {
    pst = conn.prepareStatement("SELECT * FROM Event WHERE eventID='"+tableClick+"' ");
    rs = pst.executeQuery();
    while(rs.next()){      
    JOptionPane.showMessageDialog(null, "Yess");

   }
} 

it only executed displays Yes the first time a row is clicked. Not on the second click on another row.

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by Taywin
0

Just a quick question... The eventID field type is a string or a number? Your second sql is calling as if the eventID is a string (with a pair of single quotation marks), so I am not so sure about that...

Edited by Taywin

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.