Это мой класс соединения, который мне действительно нужен, так это как мне получить данные в SharedPreference и установить их в мой String IPadd.
public class ConnectionClass {
String IPadd ="192.168.254.117";
String classs = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://"+IPadd+"/dblight";
String un = "light";
String password = "12345";
@SuppressLint("NewApi")
public Connection CONN() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conn = null;
String ConnURL = null;
try {
Class.forName(classs);
conn = DriverManager.getConnection(url, un, password);
conn = DriverManager.getConnection(ConnURL);
} catch (SQLException se) {
Log.e("ERRO", se.getMessage());
} catch (ClassNotFoundException e) {
Log.e("ERRO", e.getMessage());
} catch (Exception e) {
Log.e("ERRO", e.getMessage());
}
return conn;
}
}
Мой SharedPreference
код для установки данных
try {
String strIP = ip.getText().toString();
SharedPreferences sharedPref = getSharedPreferences(Filename, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("name", strIP);
editor.commit();
Toast.makeText(getBaseContext(), "IP Saved Successfully", Toast.LENGTH_LONG).show();
}
catch (Exception ex)
{
}