Our app should connect to a SQL Database. It is in our Network. The App should edit data in the database. We have built the connection and want to set a onclicklistener to a Button, witch causes the connection code to connect.
this is the code we have got:
public class Werte_aendern extends AppCompatActivity {
TextView tvIP;
String Textauslesen = tvIP.getText().toString();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tvIP = (TextView) findViewById(R.id.tvIP);
setContentView(R.layout.activity_werte_aendern);
}
Connection con = null;
//private static String dbHost = "192.168.40.148"; // Hostname
String dbPort = "3306"; // Port -- Standard: 3306
String dbName = "wasserwerte"; // Datenbankname
String dbUser = "App"; // Datenbankuser
String dbPass = "fruitcake"; // Datenbankpasswort
private Werte_aendern(){
try {
Class.forName("com.mysql.jdbc.Driver"); // Datenbanktreiber für JDBC Schnittstellen laden.
// Verbindung zur JDBC-Datenbank herstellen.
con = DriverManager.getConnection("jdbc:mysql://"+Textauslesen+":"+ dbPort+"/"+dbName+"?"+"user="+dbUser+"&"+"password="+dbPass);
// Statement createStatement();
// SQLiteDatabase wasserwerte =
} catch (ClassNotFoundException e) {
Toast.makeText(getApplicationContext(), "Treiber nicht gefunden", Toast.LENGTH_SHORT).show();
} catch (SQLException e) {
Toast.makeText(getApplicationContext(), "Verbindung nicht möglich", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "SQLException: " + e.getMessage(), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "SQLState: " + e.getSQLState(), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "VendorError: " + e.getErrorCode(), Toast.LENGTH_SHORT).show();
}
}
}
We are noobs, but we have to do this for a schoolproject.
Can you help us please?