java - I have checked manually in my db but my list is returning empty? -
i have tried travels db source_name, destination particular. want travels list db using prepared statement. unable same.
package com.indiabus1.dao; import java.sql.connection; import java.sql.preparedstatement; import java.sql.resultset; import java.sql.sqlexception; import java.util.arraylist; import java.util.list; import com.indiabus1.beans.*; import com.indiabus1.dao.*; import com.indiabus1.*; import com.indiabus1.dao.connectionfactory; import com.indiabus1.beans.busselectionbeans; public class busselectiondao { connection connection; public busselectiondao(){} private static connection getconnection() throws sqlexception, classnotfoundexception { connection con = connectionfactory. getinstance().getconnection(); return con; } public static list<busselectionbeans> getrecords( string s, string s2){ list<busselectionbeans> list=new arraylist<busselectionbeans>(); try{ connection con=getconnection(); system.out.println(s+" "+s2); string sql="select travels new_trips.dt_trips source_name='"+s+"' , destination_name='"+s2+"' limit 5"; preparedstatement ps=con.preparestatement(sql); //ps.setstring(1, s); // ps.setstring(2, s2); resultset rs=ps.executequery(); while(rs.next()){ busselectionbeans d=new busselectionbeans(); string x1=rs.getstring(1); // string x2=rs.getstring(1); // string x3=rs.getstring(2); d.setbusoperator(x1); // d.sets_name(x2); // d.setd_name(x3); list.add(d); } con.close(); }catch(exception e){system.out.println(e);} system.out.println(list); return list; } }
why getting list returning empty, manually sql query result given.
i've experienced in past. here things might help:
- the first thing might want double check database connection. sure connecting correct database? there cases using 2 databases , forgot change database using. e.g. official_db, official_db_test or db1 , db2.
- check parameters s , s2? there might problems values since string , might have problems during parsing.
- to determine if there values inside rs, try putting system.out.println("rs has row/s.") inside while(rs.next()){ .... };
Comments
Post a Comment