I am creating a function, where the user needs to provide the table name and the path of a json file where the values are stored, and it will be inserted to a database: insertData(String tablename, String jsonFilePath)
Now if i would have known in advance what is the number of values to be inserted, it would have been easy to create a PreparedStatement something like this:
String strQuery = "INSERT INTO tablename VALUES (?, ?)";
PreparedStatement stmt = conn.prepareStatement(strQuery);//prepare the SQL Query
stmt.setString(1, "abc");//insert homeid
stmt.setInt(2, "def");//insert featureid.
stmt.executeQuery();//execute query
But since i don't know what is the tablename in advance, and the number of columns per table may vary, how do i go ahead with it because i need to create the SQL query string "strQuery" in advance where i need to put the ?