Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JDBC通用SQL插入函数_Java_Mysql_Sql_Jdbc_Arraylist - Fatal编程技术网

Java JDBC通用SQL插入函数

Java JDBC通用SQL插入函数,java,mysql,sql,jdbc,arraylist,Java,Mysql,Sql,Jdbc,Arraylist,我正在编写一个将数据插入SQLtables的通用函数,我想知道如何改进当前的实现 我当前的函数如下所示: public void insertIntoDatabase(String table, ArrayList<String> insertRow) { .. } public void insertIntoDatabase(字符串表,ArrayList insertRow){ .. } table—SQL表的名称 insertRow-要插入的值的ArrayList 有些表还包

我正在编写一个将数据插入SQLtables的通用函数,我想知道如何改进当前的实现

我当前的函数如下所示:

public void insertIntoDatabase(String table, ArrayList<String> insertRow) {
..
}
public void insertIntoDatabase(字符串表,ArrayList insertRow){
..
}
table—SQL表的名称 insertRow-要插入的值的ArrayList

有些表还包含VARCHAR以外的其他属性,因此我正在考虑
ArrayList insertRow
但是有必要为每个数据库表编写单独的java类吗

谢谢你的帮助!
M

不能在
PreparedStatement
中绑定表名或列名

但是可以编写通用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);
};
包持久化;
公共接口通用DAO{
列表查找();
V find(K id);
K保存(V值);
无效更新(V值);
无效删除(V值);
};

为什么不使用then hibernate?谢谢。我在这里找到了一个解决方案: