I'm Trying to get my sql server information from SharedPreferences but cant seem to get it working in me connectioclass if i would do the same in een extended class it would work but for this code i dont want a extended class:
Normaly i use:
PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences sharedPreferences =
so i tryed:
Context context = this;
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
and:
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
But not working
Thi is my code:
public class ConnectionClass{
PreferenceManager.getDefaultSharedPreferences(this);
String servername = sharedPreferences.getString("SQLSERVER", "");
String databasenaam = sharedPreferences.getString("SQLDATABASE", "");
String serverusernaam = sharedPreferences.getString("SQLUSERNAAM", "");
String serverpassword = sharedPreferences.getString("SQLPASSWORD", "");
String ip = servername;
String classs = "net.sourceforge.jtds.jdbc.Driver";
String db = databasenaam ;
String un = serverusernaam;
String password = serverpassword ;
@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);
ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
+ "databaseName=" + db + ";user=" + un + ";password="
+ 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;
}
}