android连接mysql(android connect mysql)
我试图在Android应用程序中连接mysql。 以下是我的代码。 一旦我运行代码,我得到' 错误解析数据org.json.JSONException:输入结束 '错误的字符0 '。 我正在使用本教程
码
public class Test extends Activity{ /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.mainabout); String result = ""; //the year data to send ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("year","1980")); InputStream is = null; //http post try{ HttpClient httpclient = new DefaultHttpClient(); HttpGet httppost = new HttpGet("http://www.pherma.net84.net/admin/getAllPeopleBornAfter.php"); // httppost.s//setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); }catch(Exception e){ Log.e("log_tag", "Error in http connection "+e.toString()); } //convert response to string try{ BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result=sb.toString(); } catch(Exception e){ Log.e("log_tag", "Error converting result "+e.toString()); } try { JSONArray jArray = new JSONArray(result); for(int i=0;i<jArray.length();i++){ JSONObject json_data = jArray.getJSONObject(i); Log.i("log_tag","id: "+json_data.getInt("id")+ ", name: "+json_data.getString("name")+ ", sex: "+json_data.getInt("sex")+ ", birthyear: "+json_data.getInt("birthyear") ); } } catch(JSONException e){ Log.e("log_tag", "Error parsing data "+e.toString()); } } }
logcat的
php <?php mysql_connect(".com","a4055820_root",""); mysql_select_db("a4055820_pherma"); $q=mysql_query("SELECT * FROM people WHERE birthyear>'".$_REQUEST['year']."'"); while($e=mysql_fetch_assoc($q)) $output[]=$e; print(json_encode($output)); mysql_close(); ?>
im trying to connect mysql in android app. Below is my code. Once i run the code i get 'Error parsing data org.json.JSONException: End of input at character 0 of' error. I was using this tutorial
code
public class Test extends Activity{ /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.mainabout); String result = ""; //the year data to send ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("year","1980")); InputStream is = null; //http post try{ HttpClient httpclient = new DefaultHttpClient(); HttpGet httppost = new HttpGet("http://www.pherma.net84.net/admin/getAllPeopleBornAfter.php"); // httppost.s//setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); }catch(Exception e){ Log.e("log_tag", "Error in http connection "+e.toString()); } //convert response to string try{ BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result=sb.toString(); } catch(Exception e){ Log.e("log_tag", "Error converting result "+e.toString()); } try { JSONArray jArray = new JSONArray(result); for(int i=0;i<jArray.length();i++){ JSONObject json_data = jArray.getJSONObject(i); Log.i("log_tag","id: "+json_data.getInt("id")+ ", name: "+json_data.getString("name")+ ", sex: "+json_data.getInt("sex")+ ", birthyear: "+json_data.getInt("birthyear") ); } } catch(JSONException e){ Log.e("log_tag", "Error parsing data "+e.toString()); } } }
logcat
php <?php mysql_connect(".com","a4055820_root",""); mysql_select_db("a4055820_pherma"); $q=mysql_query("SELECT * FROM people WHERE birthyear>'".$_REQUEST['year']."'"); while($e=mysql_fetch_assoc($q)) $output[]=$e; print(json_encode($output)); mysql_close(); ?>
原文:https://stackoverflow.com/questions/10667128
最满意答案
实现此目标的最简单方法是使用BigQuery加载云数据存储备份的功能。 基本上只是将常规备份安排到GCS存储桶中,然后将备份从GCS加载到BigQuery中。 [ 文件 ]。
如果要使用Dataflow,可以使用Java或Python中的DatastoreIO源(对不起,这里没有PHP)。 [ 文件 ]
将查询结果读入PCollection:
Pipeline p = Pipeline.create(options); PCollection<Entity> entities = p.apply( DatastoreIO.v1().read() .withProjectId(projectId) .withQuery(myQueryObject));
然后将此PCollection写入您想要数据的任何位置。
The easiest way to achieve this is by using BigQuery's ability to load Cloud Datastore backups. Essentially just schedule a regular backup into a GCS bucket, then load the backup from GCS into BigQuery. [documentation].
If you want to use Dataflow, you can use the DatastoreIO source in Java or Python (sorry, no PHP here). [documentation]
Read results from a query into a PCollection:
Pipeline p = Pipeline.create(options); PCollection<Entity> entities = p.apply( DatastoreIO.v1().read() .withProjectId(projectId) .withQuery(myQueryObject));
Then write this PCollection to wherever you want the data.
相关问答
更多-
如何使用Dataflow执行Cloud Datastore实体的迁移?(How can I perform migration of Cloud Datastore entities using Dataflow?)[2023-01-31]
您应该能够使用DatastoreIO来操作记录并并行处理它们。 PCollectionentities = p.apply( Read.from(DatastoreIO.read() .withDataset(datasetId) .withQuery(query) .withHost(host))); p.apply( ) p.apply(DatastoreIO.writeTo(dataset) ... -
Beam确实支持从GCS写入/读取。 您只需使用TextIO类。 https://beam.apache.org/documentation/sdks/javadoc/0.2.0-incubating/org/apache/beam/sdk/io/TextIO.html 要从一个或多个文本文件读取PCollection,请使用TextIO.Read。 您可以使用TextIO.Read.from(字符串)实例化转换以指定要读取的文件的路径(例如,本地文件名或文件名模式(如果在本地运行),或者Google云存储 ...
-
看起来您的数据存储区的权限配置不正确。 以下是两条通用建议: 查看Google Cloud Dataflow安全和权限文档非常有用。 数据存储是否在您运行作业的同一项目中创建? 但是,在您的情况下,您遇到以下错误: 关联的AppEngine项目是否锁定到特定域的所有用户? 如果是这样,当前的Cloud Datastore测试版中存在一个问题,即阻止Dataflow服务帐户(例如, @cloudservices.gserviceaccount.com )访问数据。 我们可以应用临时解决方法,如果您使用OAut ...
-
我最终通过制作最小的管道集合并逐个添加依赖项来实现它,直到我找到一些有用的组合。 依赖关系如下 Flask gunicorn apache-beam[gcp]==2.6.0 oauth2client==3.0.0 google-cloud-datastore==1.3.0 google-cloud-pubsub==0.28.0 google-cloud-core==0.27.0 google-cloud==0.34.0 仍然非常沮丧的是,这些东西没有任何警告而且没有任何行动,我们的生产管道已经脱机了一个星 ...
-
我在下面列出了一个非常基本的WordCount示例示例。 请注意,您需要在Cloud Function部署中包含Java二进制文件的副本,因为它不在默认环境中。 同样,您还需要使用Cloud Function打包部署jar。 module.exports = { wordcount: function (context, data) { const spawn = require('child_process').spawn; const child = spawn( ...
-
我无法真正告诉您从单个错误中做了什么,但您可能尝试将查询中的实体从一个数据存储区实例保存到另一个数据存储区实例。 麻烦的是数据存储区实例id嵌入在每个密钥中。 所以(作为一个起点)你应该使用查询结果中的属性创建新的实体对象并保存它们。 I can't really tell what you did from a single error, but you probably tried to save entities from a query from one datastore instance to ...
-
Spring Cloud Data Flow本身没有共享存储的一般概念,但用于为PMML处理器提供模型的Spring Resource非常灵活(参见http://docs.spring.io/spring/docs/current/spring) -framework-reference / html / resources.html ,特别是表8.1,提供了一些可用于pmml.model-location参数的路径选项。 因此,开箱即用的选项有两个: 使用共享文件系统(然后可以通过file://协议访问) ...
-
将数据从Google Cloud-SQL移至Cloud Datastore(Move data from Google Cloud-SQL to Cloud Datastore)[2024-01-05]
我要求增加配额,谷歌的某人检查了我的帐户以找到问题。 这是他们的回复。 我们了解到,只要您尝试将Cloud SQL备份到Cloud Datastore,就想知道自己要达到的具体配额。 在检查您的项目时,问题似乎是您的App Engine应用程序达到或接近其支出限制。 截至本文撰写时,您执行的数据存储区写操作费用为1.10美元,将在5小时后刷新。 在补充每日支出限额之前,它肯定会导致您的资源无法使用。 请尽快尝试增加支出限额,以避免服务中断,然后运行或执行数据存储区写操作。 试一试,让我知道会发生什么。 我期 ... -
实现此目标的最简单方法是使用BigQuery加载云数据存储备份的功能。 基本上只是将常规备份安排到GCS存储桶中,然后将备份从GCS加载到BigQuery中。 [ 文件 ]。 如果要使用Dataflow,可以使用Java或Python中的DatastoreIO源(对不起,这里没有PHP)。 [ 文件 ] 将查询结果读入PCollection: Pipeline p = Pipeline.create(options); PCollection
entities = p.apply( D ... -
(1)Dataflow不支持直接从Kafka读取,但我们计划将来使用。 (2)我不太清楚你的意思。 你能提供更多细节吗? (1) Ad mentioned by Raghu, support for writing to/reading from Kafka was added to Apache Beam in mid-2016 with the KafkaIO package. You can check the package's documentation[1] to see how to use ...