本文介绍了Android的工作室MySQL不插入到数据库code看起来不错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我尝试一些价值添加到现有的数据库表。一切执行没有错误,所有的变量都是简单的字符串(选中)。也许ü可以帮助我了解那里的问题是在这里是codeS:
uzsisakyti点击:
uzsisakyti.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
ArrayList的<&的NameValuePair GT; dataToSend =新的ArrayList<>();
dataToSend.add(新BasicNameValuePair(面食,Global.elpastas));
dataToSend.add(新BasicNameValuePair(slaptazodis,Global.slaptazodis));
dataToSend.add(新BasicNameValuePair(naryste,trukme ++拉德++ kaina.getText()的toString()));
的HttpParams HTT prequestParams = getHtt prequestParams();
HttpClient的客户端=新DefaultHttpClient(HTT prequestParams);
HttpPost后=新HttpPost(SERVER_ADDRESS
+Naryste.php); 尝试{
post.setEntity(新UrlEn codedFormEntity(dataToSend));
client.execute(岗位);
}赶上(例外五){
e.printStackTrace();
}
}
私人的HttpParams getHtt prequestParams(){
的HttpParams HTT prequestParams =新BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(HTT prequestParams,CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(HTT prequestParams,CONNECTION_TIMEOUT);
返回HTT prequestParams;
}
});
php文件:
< PHP
$ CON = mysqli_connect(mysql10.000webhost.com,*,*,*); $面食= $ _ POST [面食];
$ slaptazodis = $ _ POST [slaptazodis]
$奈良= $ _ POST [naryste]; $声明= mysqli_ prepare($ CON,更新用户设置naryste ='$奈良'WHERE面食='$面食'AND slaptazodis ='$ slaptazodis');
mysqli_stmt_execute($语句); mysqli_stmt_close($语句); mysqli_close($ CON);
?>
logcat的:
06-02 17:05:04.350 9381-9381 / com.tonikamitv.loginregister W / System.err的:android.os.NetworkOnMainThreadException
06-02 17:05:04.350 9381-9381 / com.tonikamitv.loginregister W / System.err的:在android.os.StrictMode $ AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
06-02 17:05:04.350 9381-9381 / com.tonikamitv.loginregister W / System.err的:在java.net.InetAddress.lookupHostByName(InetAddress.java:385)
06-02 17:05:04.350 9381-9381 / com.tonikamitv.loginregister W / System.err的:在java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
06-02 17:05:04.350 9381-9381 / com.tonikamitv.loginregister W / System.err的:在java.net.InetAddress.getAllByName(InetAddress.java:214)
06-02 17:05:04.350 9381-9381 / com.tonikamitv.loginregister W / System.err的:在org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
06-02 17:05:04.350 9381-9381 / com.tonikamitv.loginregister W / System.err的:在org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
06-02 17:05:04.350 9381-9381 / com.tonikamitv.loginregister W / System.err的:在org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
06-02 17:05:04.350 9381-9381 / com.tonikamitv.loginregister W / System.err的:在org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
06-02 17:05:04.350 9381-9381 / com.tonikamitv.loginregister W / System.err的:在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
06-02 17:05:04.350 9381-9381 / com.tonikamitv.loginregister W / System.err的:在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
06-02 17:05:04.350 9381-9381 / com.tonikamitv.loginregister W / System.err的:在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
06-02 17:05:04.350 9381-9381 / com.tonikamitv.loginregister W / System.err的:在com.tonikamitv.loginregister.Naryste $ 3.onClick(Naryste.java:86)
06-02 17:05:04.360 9381-9381 / com.tonikamitv.loginregister W / System.err的:在android.view.View.performClick(View.java:4191)
06-02 17:05:04.360 9381-9381 / com.tonikamitv.loginregister W / System.err的:在android.view.View $ PerformClick.run(View.java:17229)
06-02 17:05:04.360 9381-9381 / com.tonikamitv.loginregister W / System.err的:在android.os.Handler.handleCallback(Handler.java:615)
06-02 17:05:04.360 9381-9381 / com.tonikamitv.loginregister W / System.err的:在android.os.Handler.dispatchMessage(Handler.java:92)
06-02 17:05:04.360 9381-9381 / com.tonikamitv.loginregister W / System.err的:在android.os.Looper.loop(Looper.java:137)
06-02 17:05:04.360 9381-9381 / com.tonikamitv.loginregister W / System.err的:在android.app.ActivityThread.main(ActivityThread.java:4960)
06-02 17:05:04.360 9381-9381 / com.tonikamitv.loginregister W / System.err的:在java.lang.reflect.Method.invokeNative(本机方法)
06-02 17:05:04.360 9381-9381 / com.tonikamitv.loginregister W / System.err的:在java.lang.reflect.Method.invoke(Method.java:511)
06-02 17:05:04.360 9381-9381 / com.tonikamitv.loginregister W / System.err的:在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1038)
06-02 17:05:04.360 9381-9381 / com.tonikamitv.loginregister W / System.err的:在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
06-02 17:05:04.360 9381-9381 / com.tonikamitv.loginregister W / System.err的:在dalvik.system.NativeStart.main(本机方法)
解决方案
INSERT INTO用户naryste价值观奈良WHERE面食= $面食和slaptazodis = $ slaptazodis
错
正确的语法是 INSERT INTO用户设定面食=$面食,slaptazodis =$ slaptazodis,naryste =$ naryste
但它确实取决于表结构所使用。
Hello I am trying to add some value to my existing database table. Everything executes without errors, all variables are simple strings (checked). Maybe U can help me understand where the problem is here is the codes:
uzsisakyti click :
uzsisakyti.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ArrayList<NameValuePair> dataToSend = new ArrayList<>();
dataToSend.add(new BasicNameValuePair("pastas",Global.elpastas ));
dataToSend.add(new BasicNameValuePair("slaptazodis",Global.slaptazodis ));
dataToSend.add(new BasicNameValuePair("naryste",trukme +" "+ "rad" +" "+ kaina.getText().toString()));
HttpParams httpRequestParams = getHttpRequestParams();
HttpClient client = new DefaultHttpClient(httpRequestParams);
HttpPost post = new HttpPost(SERVER_ADDRESS
+ "Naryste.php");
try {
post.setEntity(new UrlEncodedFormEntity(dataToSend));
client.execute(post);
} catch (Exception e) {
e.printStackTrace();
}
}
private HttpParams getHttpRequestParams() {
HttpParams httpRequestParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpRequestParams,CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpRequestParams,CONNECTION_TIMEOUT);
return httpRequestParams;
}
});
php file :
<?php
$con=mysqli_connect("mysql10.000webhost.com","*","*","*");
$pastas = $_POST["pastas"];
$slaptazodis = $_POST["slaptazodis"]
$nara = $_POST["naryste"];
$statement = mysqli_prepare($con, "UPDATE User SET naryste='$nara' WHERE pastas='$pastas' AND slaptazodis= '$slaptazodis'");
mysqli_stmt_execute($statement);
mysqli_stmt_close($statement);
mysqli_close($con);
?>
Logcat :
06-02 17:05:04.350 9381-9381/com.tonikamitv.loginregister W/System.err﹕ android.os.NetworkOnMainThreadException
06-02 17:05:04.350 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
06-02 17:05:04.350 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
06-02 17:05:04.350 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
06-02 17:05:04.350 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at java.net.InetAddress.getAllByName(InetAddress.java:214)
06-02 17:05:04.350 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
06-02 17:05:04.350 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
06-02 17:05:04.350 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
06-02 17:05:04.350 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
06-02 17:05:04.350 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
06-02 17:05:04.350 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
06-02 17:05:04.350 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
06-02 17:05:04.350 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at com.tonikamitv.loginregister.Naryste$3.onClick(Naryste.java:86)
06-02 17:05:04.360 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at android.view.View.performClick(View.java:4191)
06-02 17:05:04.360 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at android.view.View$PerformClick.run(View.java:17229)
06-02 17:05:04.360 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:615)
06-02 17:05:04.360 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:92)
06-02 17:05:04.360 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at android.os.Looper.loop(Looper.java:137)
06-02 17:05:04.360 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:4960)
06-02 17:05:04.360 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
06-02 17:05:04.360 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511)
06-02 17:05:04.360 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
06-02 17:05:04.360 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
06-02 17:05:04.360 9381-9381/com.tonikamitv.loginregister W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
解决方案
INSERT INTO User naryste VALUES nara WHERE pastas= $pastas AND slaptazodis= $slaptazodis
is wrong
Correct syntax is INSERT INTO User SET pastas="$pastas", slaptazodis="$slaptazodis", naryste="$naryste"
but it really depends on the table structure you are using.
这篇关于Android的工作室MySQL不插入到数据库code看起来不错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!