0

I am writing a generic function to insert data into SQLtables and I am wondering how to improve my current implementation.

My current function looks like:

public void insertIntoDatabase(String table, ArrayList<String> insertRow) {
..
}

table - Name of the SQL table insertRow - ArrayList of values to insert

Some tables also contain other attributes than VARCHARS so I am considering ArrayList<xtable> insertRow But is it necessary to write individual java classes for each database table ?

Thanks for your help! M

duffymo
  • 305,152
  • 44
  • 369
  • 561
user3703592
  • 160
  • 8

1 Answers1

0

You can't bind table or column names in PreparedStatement.

But it is possible to write a generic DAO:

package persistence;

public interface GenericDao<K, V> {
    List<V> find();
    V find(K id);
    K save(V value);
    void update(V value);
    void delete(V value);
};
duffymo
  • 305,152
  • 44
  • 369
  • 561
  • Thanks . One solution I found here: http://stackoverflow.com/questions/10872919/separating-sql-from-the-java-code – user3703592 Jun 23 '14 at 13:25