I have a ListView
with multiple rows. When I insert the entries in the ListView into an sql database, all the entries get inserted into a single row.
I get all the entries from the view with a String builder.
How can I solve this problem?
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
StringBuilder sb3 = new StringBuilder();
//get data form text view
for(int i=0; i<simpleAdapter.getCount(); i++) {
String a = ((TextView) findViewById(R.id.al)).getText().toString();
String b = ((TextView) findViewById(R.id.sh)).getText().toString();
String c = ((TextView) findViewById(R.id.acc)).getText().toString();
simpleAdapter.getItem(i).toString();
sb.append(a);
sb.append("\n");
sb2.append(b);
sb2.append("\n");
sb3.append(c);
sb3.append("\n");
}
String text = sb.toString();
String text2 = sb2.toString();
String text3 = sb3.toString();
//my sql connection insert query
try {
Connection con = connectionClass.CONN();
if (con == null) {
Toast.makeText(getApplicationContext(), "Error in connection with SQL server", Toast.LENGTH_LONG).show();
} else {
String query = "INSERT INTO suigen.TransAlmiraShelf (Almira, Shelf, AccessionNo) VALUES('" + String.valueOf(text) + "','" + String.valueOf(text2) + "','" + String.valueOf(text3) + "')";
Statement stmt = con.createStatement();
stmt.execute(query);
Toast.makeText(Main13Activity.this, "Your Data Successfully Saved", Toast.LENGTH_LONG).show();
}
}
catch (Exception ex) {
Toast.makeText(getApplicationContext(), "Exceptions", Toast.LENGTH_LONG).show();
}