English 中文(简体)
甲型六氯环己烷[复制]问题
原标题:Problem with alphabetic sorting [duplicate]
  • 时间:2011-04-02 05:44:00
  •  标签:
  • java
  • sql
  • jdbc

我使用了LIKE这一条件,但要求我把全名输入数据库,以找到名字。

if (searchby.equals("Name"))
{
    try
    {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        System.out.println("
 Driver loaded");
        Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
        Statement stmt=con.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT Name FROM FAMILYcensus WHERE Name LIKE  "+ tfsearch.getText()+" ");
        //  ResultSet rs = stmt.executeQuery("SELECT Name FROM FAMILYcensus WHERE Name LIKE );
        System.out.println("Hi");

        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);
    }
问题回答

WhiteFang34还说,你需要振兴。 但是,你还需要修改《家庭平等法》条款:

"SELECT * FROM FAMILYcensus WHERE Name >  "+ tfsearch.getText()+"  ORDER BY Name ASC LIMIT "+MAXRESULTS;

请注意,限制结果数目是这方面的一个好想法。

3. 你们需要抓住成果:

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

它同你一样,评论了它吗? 如果你想将其储存在名单上,你就有权这样做。 如果你想把所有结果都列入<编码>String>,tasearch.setText():

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

StringBuilder sb = new StringBuilder();

以及

sb.append(name + " ");

do

List names = new ArrayList<String>();

以及

names.add(name);

不这样做:

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

使用:

List<String> lstNames = new ArrayList<String>();
while (rs.next()) {
   lstNames.add(rs.getString("Name"));
}

我确实不明白你的问题,但从我的理解来看,我搁置可能有助于解决你的问题。

Put per cent as EmCo comment %”+ tfsearch.getText()+%“

搜查前后的百分率在你发现其中之一时有不同的用途。 见。 功能比较 如何使用。

现在,你的另一个问题是:

你希望按字母顺序命名。 为此,请列入<代码>。 页: 1 然后,你将提出疑问。

"SELECT 
        Name 
   FROM FAMILYcensus 
  WHERE Name LIKE  %" + tfsearch.getText() +"%  
  ORDER BY Name ASC"

你的搜查可能导致不止一次。 仅使用<代码>s.next();和String name = rs.getString("NAME”);将只取得第一批记录I guess。

You can try this code:

List<String> names = new ArrayList<String>();
while(rs.next){
    names.add(rs.getString( Name ));
}

所提供的代码I ve没有经过测试。 虽然情况类似。 如果你仍然对现行法典有问题的话,就会尝试。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签