[英]How to display data from sql server with java [android studio]
I wish to display some data from my SQL server into my application. 我希望将一些数据从我的SQL Server显示到我的应用程序中。
Let me explain throw an example what have i done until now, and please tell me how should i go on with my work: 让我解释一个例子,说明我到目前为止所完成的工作,然后告诉我应该如何进行工作:
(1) I have a database named: 'DB1' (2) In my database i have table named 'users': (1)我有一个名为“ DB1”的数据库(2)在我的数据库中,有一个名为“ users”的表:
Id, Name, LastName
1 Dave Stone
2 Rose Mary
3 Gray Lone
(3) I created 3 php files: 1/ config.php (sets up my database log in information like password...) 2/ DBConnection.php : ` (3)我创建了3个php文件:1 / config.php(设置数据库登录信息,例如密码...)2 / DBConnection.php:
// Connecting to database
public function connect() {
require_once 'Config.php';
// Connecting to mysql database
$this->conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
// return database handler
return $this->conn;
}
}
?>
3/ GetUsers.php which i dont know how should i write it - this would be the code which will echo whatever i want from the table. 3 / GetUsers.php,我不知道该怎么写- 这将是代码,它将回显我想要的表内容。
(4) Inside my android studio project i have a MainActivity.java and i want to get all the LastNames of all the users in the database and do whatever with them... like print them into a text box it doesn't really matter (let's say i don't know how many users I have). (4)在我的android studio项目中,我有一个MainActivity.java,我想获取数据库中所有用户的所有姓氏,并对其进行任何处理……就像将它们打印到文本框中一样,这并不重要(假设我不知道我有多少用户)。
I need some one to help me get stages (3)3/ + (4) done / explained. 我需要一些人来帮助我完成(3)3 / +(4)阶段的工作/解释。
I think what you mean is a good method to retrieve and set values from app to database, the best and most prominent way is using basic REST services that convert your db values to JSON then you load the json using your api key as authentication, it might sound really stressful but is in fact very easy and flexible to implement, the only way you can directly set and get db values on android is using sqlite (android local inbuilt db) 我认为您的意思是从应用程序检索和设置值到数据库的好方法,最好和最主要的方法是使用基本的REST服务,将db值转换为JSON,然后使用api密钥作为身份验证来加载json,听起来可能有些压力,但实际上实施起来非常容易且灵活,您可以在android上直接设置和获取db值的唯一方法是使用sqlite(Android本地内置db)
The best tutorial and major explanation for exactly what you want to achieve is here 有关您想要实现的目标的最佳教程和主要解释在这里
http://www.androidhive.info/2014/01/how-to-create-rest-api-for-android-app-using-php-slim-and-mysql-day-12-2/ http://www.androidhive.info/2014/01/how-to-create-rest-api-for-android-app-using-php-slim-and-mysql-day-12-2/
Then this one for further works http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/ 然后,这个用于进一步的工作http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/
It covers how you make a rest service yourself 它涵盖了您如何自己提供休息服务
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.