Android - 从mysql数据库搜索填充编辑文本视图

时间:2014-11-29 14:02:22

标签: java android mysql database search

我是java的新手,如果这没有意义,请原谅我。我正在尝试创建一个简单的Android应用程序,用户可以在其中输入部门名称,然后单击搜索按钮。然后,它将从mysql数据库中检索数据,并使用该信息填充下面的编辑文本框。

到目前为止,我已将数据库连接到我的应用程序:

db.java

public class db {
public static Connection con;
public static void main(String[] argv) {
  try
    {
        connectionQuery();

        PreparedStatement statement =  con.prepareStatement("SELECT * from buildings");/*write query inside of prepared statement*/
        ResultSet result = statement.executeQuery();
        System.out.println("DataBase table accessed");

        while(result.next())
        {
           String retrievedid= result.getString("name");

           System.out.println(retrievedid);
        }


        con.close();
    }

    catch(Exception e)
    {
        e.printStackTrace();
        System.out.println(e.getMessage().toString());
    }
 }
public static void connectionQuery()
{
    try
    {
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/fypdb","root","");
        System.out.println("Remote DB connection established");
    }
    catch (ClassNotFoundException e)
    {
        e.printStackTrace();
        System.out.println("Remote server could not be connected");
    }
    catch (NullPointerException e)
    {
        e.printStackTrace();
        System.out.println("Remote server could not be connected");
    }
    catch (SQLException e)
    {
        e.printStackTrace();
        System.out.println("Remote db connection establishment error");
    }
    catch (Exception e)
    {
        e.printStackTrace();
        System.out.println("False query");
    }

}
}

这很好,打印出结果。

但现在我不知道如何从应用程序中搜索数据库并使用结果填充编辑文本视图。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

首先,mysql数据库不属于操作系统的一部分...如果你设法运行那么请让我知道..还要google人......

android支持SQLITE3数据库你应该尝试使用它来改进android操作系统

如果我错了请纠正我