WebMehod that return List

Closed
leilusha Posts 19 Registration date Tuesday June 3, 2014 Status Member Last seen February 22, 2017 - Oct 30, 2015 at 06:07 PM
 Blocked Profile - Oct 31, 2015 at 06:57 PM
Hello,

My webMethod should returns table from database in a List

@WebMethod(operationName = "affTable")
    public List affTable(@WebParam(name = "nameT") String nameT, @WebParam(name = "nameBDD") String nameBDD) throws IOException
    {
        try
        {
            Class.forName( "com.mysql.jdbc.Driver" );
            conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/"+nameBDD,"root","");
            pst=conn.createStatement();
            rs=pst.executeQuery("select *  from "+nameT);
            Tab = net.proteanit.sql.DbUtils.resultSetToNestedList(rs);      
        }
        catch(Exception e)
        {
            System.out.println(" Echec !");
            e.printStackTrace();
        }
    return Tab;
    }  


But it returns errors , where is the problem plz ? Thank You

3 responses

Blocked Profile
Oct 30, 2015 at 07:05 PM
Well, an SQL statement usually ends with a ";".

Your variable QUERY statement would actually be interpreted as:

"select * from tblGOBLYSTUFF"

if nameT = "tblGOBLYSTUFF".

You may need to append the SQL with an additional +";" behind the nameT within the SQL select statement.

But, then again, you did not tell us where the error was being thrown. From the connection, the SQL SELECT, or the syntax?

Let us know what you try and find!
I have said it once, I will say it again. IT!
1
leilusha Posts 19 Registration date Tuesday June 3, 2014 Status Member Last seen February 22, 2017
Oct 31, 2015 at 06:41 AM
okay, i tried
"select *  from "+nameT+";"
but it didn't work
then i tried this
"select *  from '"+nameT+"'"
and it works -> there is no errors thank you,

but the return was like this :

Method returned

java.util.List : "[]"


where is the contents of my List?
0
Blocked Profile
Oct 31, 2015 at 06:57 PM
Well, you have to "provision" (set) and array of the return.

Dim therecords_index0(99)
Dim therecords_index1(99)
a=0
DO WHILE NOT rs.EOF
therecords_index0(a)=rs(0)
therecords_index1(a)=rs(1)
RS.MOVENEXT 'loops through the next record or throws EOF
a=a+1 'add one to value a whichcounts the array index
LOOP 'will loop as long as not EOF


This will only store 99 records. Please notice that you will only be returning the first two index values of the table.

Once again, this is not the same language, but it should be able to give you direction.
0