Mirwais Faizi
Mirwais Faizi

Reputation: 17

how to concatenate two rows in java?

   public void ReserveTimeList(){ 
    String sql = "select to_char(to_char(start_time,'HH24:MI') ||' - '|| 
    to_char(end_time,'HH24:MI')) from register_table";
    try {
        DefaultListModel dlm = new DefaultListModel();
        pst = conn.prepareStatement(sql);
        rs = pst.executeQuery();
        while(rs.next()){

             //SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
           //  dlm.addElement(format.parseObject(rs.getString("time")));

   dlm.addElement(rs.getString("to_char(to_char(start_time,'HH24:MI') ||' - 
   '|| to_char(end_time,'HH24:MI'))"));
            lstResTime.setModel(dlm);
        }
       } catch (SQLException ex) {
          Logger.getLogger(Time_Setting.class.getName()).log(Level.SEVERE, 
       null, ex);
      }

    }

The program is correct but i don't know what's the problem, When I run the program the Exception arias :java.sql.SQLException: Invalid column name

Upvotes: 1

Views: 222

Answers (1)

Ori Marko
Ori Marko

Reputation: 58772

I would add an alias, e.g. my_time

String sql = "select to_char(to_char(start_time,'HH24:MI') ||' - '|| 
    to_char(end_time,'HH24:MI')) as my_time from register_table";
 //...

 dlm.addElement(rs.getString("my_time"))l

Upvotes: 2

Related Questions