有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法从数据库结果集设置Textview文本

无法从数据库结果集设置文本视图。没有错误,但文本视图文本未更新。查询后代码块内的任何文本框,不动态设置值。为什么它似乎完全跳过了“try”条款

这是我的密码

  protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            connectionClass = new ConnectionClass(); //the class file
            tripid=(TextView) findViewById(R.id.tripid);           
            tripname();
    }
    private void tripname() {
            try {
                Connection con = connectionClass.CONN();
                if (con == null) {

                } else {
                    String query = "select * from tblTrip where TripId ='" + tripid+ "'";
                    PreparedStatement ps = con.prepareStatement(query);
                    ResultSet rs = ps.executeQuery();

                    name = rs.getString(2);
                    TextView tripname = (TextView) findViewById(R.id.tripname);
                    tripname .setText(name);

     TextView name= (TextView) findViewById(R.id.name);
                    name .setText("tri");
                }
            } catch (Exception ex) {
      System.out.println("Error " + ex.getMessage());
            }


        }

共 (1) 个答案

  1. # 1 楼答案

    也许你可以在后台线程中获得数据库结果集,然后你必须从UI线程更新日期