Android/java Jdbc Mysql - Fetch Rows - Effective Algorithm
I am trying to write an app as an mysql client and I ran into way, which I don't want to follow, because I think, it is not a good one, even if it is possible. I have JDBC driver i
Solution 1:
If you only need the string representation of all the values in all the columns, you can use the ResultSet
getString(int index)
method. The values will be converted to String
no matter the type of the columns.
Here is an example:
try (Connection con = getDatabaseConnection();) {
try (Statement st = con.createStatement();) {
try (ResultSet rs = st.executeQuery("SELECT * FROM TableName");) {
ArrayList<ArrayList<String>> rows = new ArrayList<ArrayList<String>>();
while (rs.next()) {
ArrayList<String> row = new ArrayList<String>();
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
row.add(rs.getString(i + 1));
}
rows.add(row);
}
System.out.println(rows);
}
}
} catch (Exception e) {
e.printStackTrace();
}
Post a Comment for "Android/java Jdbc Mysql - Fetch Rows - Effective Algorithm"