0

Hye,i have problem with looping....

this is my coding for now.

try{
                                 Class.forName("com.mysql.jdbc.Driver");
                                 Connection con = DriverManager.getConnection("jdbc:mysql://localhost/finalproject", "root", "Amillia89");
                                 Statement stmt=con.createStatement();
                                // String pick = "select * from synonym where words like= "+st+"% ";
                                  ResultSet rs=stmt.executeQuery("select * from synonym where words like \""+st+"%\"");
                                  String words="";
                                  if(rs.next()){
                                    words=rs.getString("words");
                                    ResultSetMetaData rsmd = rs.getMetaData();
                            int col = rsmd.getColumnCount();
                            int count=0;
               
                    while(rs.next()) {
                    for (int i=1;i<col;i++){
                 
                    count++;
                    }

                    String [] test = new String[count];
                    for(int a =1 ; a<count; a++)
                  {
                        for (int i=1;i<col;i++)
                            test[a] = rs.getString(i);
                  }

                    for(int a =1 ; a<count; a++)
                  {
                        System.out.println(test[a]);
                   }                                   
                                     
                         }

                     }

                 }
    catch(Exception ie)
    {
    ie.printStackTrace();
    }
                          }
                         });

but the problem is, when i run this program,it keeps add the number of words.
for example, i choose alphabet using Jcombobox but the result is...

A BB CCC DDDD EEEEE FFFFFF GGGGGGG HHHHHHHH......... instead of ABCDEFGH........

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

What's the point of this code?

for (int i=1;i<col;i++) 
   test[a] = rs.getString(i);

Isn't that just the same as

test[a] = rs.getString(col-1);

but without all the overwriting of previous entries?

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.