Привет, я пытаюсь подключить мое приложение для Android к базе данных mysql
, но я получаю это exception
, в то время как отладка может помочь любому, пожалуйста, помогите мне.
Исключение:
java.io.IOException: неожиданное завершение потока в соединении {192.168.43.110:3306, прокси = DIRECT @ hostAddress = 192.168.43.110 cipherSuite = нет протокол = http / 1.1} (счетчик циклов = 0)
package com.kulibrary.www.mainku;
import android.content.Intent;
import android.preference.EditTextPreference;
import android.provider.MediaStore;
import android.widget.Toast;
import java.io.*;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.ProgressDialog;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Button;
import android.util.Log;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AdapterView.OnItemSelectedListener;
import android.os.AsyncTask;
import java.net.HttpURLConnection;
import java.net.URL;
public class reg extends AppCompatActivity {
public TextView already_text;
public Button Signup_button;
public RadioGroup radiogroup;
public RadioButton Radio_button;
public Spinner Spin_text;
public EditText name_tex;
public EditText id_t;
public EditText email_t;
public EditText pswd_t;
public EditText phone_t;
private static final String REGISTER_URL = "http://192.168.43.110:3306/php1.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reg);
Signup_button = (Button) findViewById(R.id.button);
already_text = (TextView) findViewById(R.id.text_already);
// Radio_Lib=(RadioButton) findViewById(R.id.radio_lib);
name_tex = (EditText) findViewById(R.id.name_edit);
id_t = (EditText) findViewById(R.id.id_edit);
email_t = (EditText) findViewById(R.id.email_edit);
pswd_t = (EditText) findViewById(R.id.pswd_txt);
phone_t = (EditText) findViewById(R.id.phone_edit);
Spin_text = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.book_name));
myAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spin_text.setAdapter(myAdapter);
radiogroup = (RadioGroup) findViewById(R.id.radio_group);
radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Radio_button = (RadioButton) findViewById(checkedId);
switch (Radio_button.getId()) {
case R.id.radio_stu: {
if (Radio_button.isChecked()) {
Log.d("RD", "STUDENT");
}
break;
}
case R.id.radio_lib: {
if (Radio_button.isChecked()) {
Log.d("RD", "LIBRARIYAN");
}
break;
}
}
}
});
already_text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(reg.this, LoginActivity.class);
startActivity(intent);
}
});
Signup_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registerUser();
}
private void registerUser() {
String type = Radio_button.getText().toString().trim().toLowerCase();
String name = name_tex.getText().toString().trim().toLowerCase();
String department = Spin_text.getSelectedItem().toString().trim().toLowerCase();
String id = id_t.getText().toString().trim().toLowerCase();
String email = email_t.getText().toString().trim().toLowerCase();
String password = pswd_t.getText().toString().trim().toLowerCase();
String phone = phone_t.getText().toString().trim().toLowerCase();
register(type, name, department, id, email, password, phone);
}
private void register(String type, String name, String department, String id, String email, String password, String phone) {
String urlSuffix = "?type=" + type + "&name=" + name + "&department=" + department + "&id=" + id + "&email=" + email + "&password=" + password + "&phone=" + phone;
class RegisterUser extends AsyncTask<String, Void, String> {
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(reg.this, "Please Wait", null, true, true);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(getApplicationContext(), "Registered", Toast.LENGTH_SHORT).show();
}
@Override
protected String doInBackground(String... params) {
String s = params[0];
BufferedReader bufferReader = null;
try {
URL url = new URL(REGISTER_URL + s);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
bufferReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String result;
result = bufferReader.readLine();
return result;
} catch (Exception e) {
return null;
}
}
}
RegisterUser ur = new RegisterUser();
ur.execute(urlSuffix);
}
});
}
}
php код:
<?php
define('HOST','localhost');
define('USER','root');
define('PASS','54321');
define('DB','login');
$con = mysqli_connect(HOST,USER,PASS,DB);
$typ = $_GET['type'];
$nam = $_GET['name'];
$dep = $_GET['department'];
$idno = $_GET['id'];
$email = $_GET['email'];
$pass = $_GET['password'];
$phno = $_GET['phone'];
if($typ == '' || $nam == '' || $dep==''||$idno == ''||$email == '' || $pass == '' || $phno == '')
{
echo 'please fill all values';
}
else{
$sql = "SELECT * FROM signup2 WHERE id='$idno' " ;
$check = mysqli_fetch_array(mysqli_query($con,$sql));
if(isset($check))
{
echo 'ID already exist';
}
else
{
$sql = "INSERT INTO signup2 (typ,nam,dep,id,ema,pass,phn) VALUES('$typ','$nam','$dep','$idno','$email','$pass','$phno')";
if( mysqli_query($con,$sql))
{
echo 'successfully registered';
}
else
{
echo 'oops! Please try again!';
}
}
mysqli_close($con);
}
?>