我需要使用java將csv導入到訪問數據庫中。我試着用下面的代碼使用java將csv文件中的數據導入到訪問數據庫中
我的代碼:
public static void main (String args[])
{
String dbFileSpec = "C:\\Documents and Settings\\admin\\My Documents\\NetBeansProjects\\AutomateExcelDatabase\\Centre.accdb";
// String accessTableName = "Centre";
String csvDirPath = "C:\\Documents and Settings\\admin\\My Documents\\NetBeansProjects\\AutomateExcelDatabase";
String csvFileName = "myjdbcfile.csv";
try (Connection conn = DriverManager.getConnection(
"jdbc:ucanaccess://" + dbFileSpec
// + ";newdatabaseversion=V2007"
)) {
try
{
String strSQL = "SELECT * INTO " + dbFileSpec + " FROM [Text;HDR=YES;DATABASE=" + csvDirPath + ";].[" + csvFileName + "]";
System.err.println("SQL --> "+strSQL);
PreparedStatement selectPrepSt = conn.prepareStatement(strSQL);
boolean result = selectPrepSt.execute();
System.out.println("result = " + result);
}
catch(SQLException ex)
{
System.err.println("Error --->"+ex.toString());
}
conn.commit();
conn.close();
} catch (SQLException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
但它拋出錯誤爲 「net.ucanaccess.jdbc.UcanaccessSQLException:意外的標記:成所需要的:FROM」。
通過使用它produceserror「net.ucanaccess.jdbc.UcanaccessSQLException:意外的令牌::」 – Dhinakar 2014-10-30 09:37:41
我很擔心。爲什麼你讓你的簡單的'select'語句如此複雜 – 2014-10-30 09:39:53
它並不複雜,但它是拋出錯誤 – Dhinakar 2014-10-30 09:48:16