需要一个代码

时间:2011-04-04 04:43:53

标签: java

  

可能重复:
  Problem with alphabetic sorting
  i want to search the name alphabetically required query for that

先生我用字母搜索人名,我的代码也按字母搜索结果,但我得到的结果是字符串的意思(所有名字在同一行)但我想在列表中回答帮助我 我的代码是:

 if(searchby.equals("Name"))

        {
             try
            {

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            System.out.println("\n Driver loaded");
            Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
            Statement stmt=con.createStatement();

           // ResultSet rs = stmt.executeQuery("SELECT * FROM FAMILYcensus WHERE Name > '"+ tfsearch.getText()+"' ORDER BY Name ASC"+MAXRESULTS);
            ResultSet rs = stmt.executeQuery("SELECT * FROM FAMILYcensus WHERE Name LIKE '"+ tfsearch.getText()+"%'ORDER BY Name ASC");
            System.out.println("Hi");






//            while (rs.next()) {
//            String  names = rs.getString("Name");
//            System.out.println("Name: " + names);
//            }

             StringBuilder sb = new StringBuilder();
             while (rs.next()) {
             String name = rs.getString("Name");
             sb.append(name + " ");
             }
            String names = sb.toString().trim();


//            rs.next();
//            String names = rs.getString("Name");
//            System.out.println("Name: " + names );

            JOptionPane.showMessageDialog(null, "RECORD FOUND");


           tasearch.setText(names);
            }

           catch (Exception e)
           {
            System.out.println("EXCEPTION " + e);

           }
       }

0 个答案:

没有答案