I am using Spring 3.1.2 and Hibernate 4.1.5_SP1. I am trying to import CSV files into dynamically created Access files. The code looks similar to this:
final SingleConnectionDataSource ds = new SingleConnectionDataSource();
ds.setUrl(myBean.getMicrosoftAccessDriverUrl() + file.getAbsolutePath());
final JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
final String strSQL = "SELECT * INTO " + accessTableName + " FROM
[Text;HDR=YES;DATABASE=" + csvFile.getPath()+ ";].[" +
csvFile.getName() + "]";
jdbcTemplate.execute(strSQL);
ds.getConnection().close();
Which generates an error like:
org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad
SQL grammar
[SELECT * INTO myTable
FROM [Text;HDR=YES;DATABASE=C:\somePath;].[myAccessFile.accdb]];
nested exception is java.sql.SQLException: [Microsoft][ODBC Microsoft
Access Driver] Cannot update. Database or object is read-only.
My Datasource URL is similar to:
jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\somePath\myAccessFile.accdb
I checked the files and they are NOT read-only. Any suggestions on how to solve this?
Thanks!
The
FROMclause does not look correct to me.I thought you intended to import from CSV into an Access table. If so, I think you should be using the CSV file name in place of the Access file (
myAccessFile.accdb).