<p>I posted the code below to the Sun developers forum since I thought it was erroring (the true error was before this code was even hit).  One of the responses I got said it would not work and to throw it away.  But it is actually working.  It might not be the best code (I am new to Java) but is there something inherently "wrong" with it? </p>

<p>=============</p>

<p>CODE:
<pre></p>

<code>private static void ImportFromCsvToAccessTable(String mdbFilePath, String accessTableName 
, String csvDirPath , String csvFileName ) throws ClassNotFoundException, SQLException {

    Connection msConn = getDestinationConnection(mdbFilePath);
    try{

        String strSQL = "SELECT * INTO " + accessTableName + " FROM [Text;HDR=YES;DATABASE=" + csvDirPath + ";].[" + csvFileName + "]";
        PreparedStatement selectPrepSt = msConn.prepareStatement(strSQL );
        boolean result = selectPrepSt.execute();        
        System.out.println( "result = " + result );

    } catch(Exception e) {
        System.out.println(e);
    } finally {
        msConn.close();
    }
}
</code></pre>

[{'answer_id': 30720, 'author': 'Leigh Caldwell', 'author_id': 3267, 'author_profile': 'https://Stackoverflow.com/users/3267', 'pm_score': 3, 'selected': False, 'text': '<p>The literal answer is no - there is never anything "inherently wrong" with code, it\'s a matter of whether it meets the requirements - which may or may not include being maintainable, secure, robust or fast.</p>\n\n<p>The code you are running is actually a JET query purely within Access - the Java code is doing nothing except telling Access to run the query.</p>\n\n<p>On the one hand, if it ain\'t broke don\'t fix it. On the other hand, there\'s a good chance it will break in the near future so you could try fixing it in advance.</p>\n\n<p>The two likely reasons it might break are:</p>\n\n<ol>\n<li>SQL injection risk. Depending on where csvDirPath and csvFileName come from (e.g. csvFileName might come from the name of the file uploaded by a user?), and on how clever the Access JDBC driver is, you could be open to someone breaking or deleting your data by inserting a semicolon (or some brackets to make a subquery) and some additional SQL commands into the query.</li>\n<li>You are relying on the columns of the CSV file being compatible with the columns of the Access table. If you have unchecked CSV being uploaded, or if the CSV generator has a particular way of handling nulls, or if you one day get an unusual date or number format, you may get an error on inserting into the Access table.</li>\n</ol>\n\n<p>Having said all that, we are all about pragmatism here. If the above code is from a utility class which you are going to use by hand a few times a week/month/year/ever, then it isn\'t really a problem.</p>\n\n<p>If it is a class which forms part of a web application, then the \'official\' Java way to do it would be to read records out of the CSV file (either using a CSV parser or a CSV/text JDBC driver), get the columns out of the recordset, do some validation or sanity checking on them, and then use a new PreparedStatement to insert them into the Access database. Much more trouble but much more robust.</p>\n\n<p>You can probably find a combination of tools (e.g. object-relational layers or other data access tools) which will do a lot of that for you, but setting up the tools is going to be as much hassle as writing the code. Then again, you\'ll learn a lot from either one.</p>\n'}, {'answer_id': 31611, 'author': 'Joshua McKinnon', 'author_id': 235, 'author_profile': 'https://Stackoverflow.com/users/235', 'pm_score': 2, 'selected': False, 'text': '<p>One word of warning - jdbc -> Access queries (which bridge using odbc) do not work on 64 bit systems, as there exist no 64 bit Access database drivers (The driver is included into 32 bit copies of Windows and can only be accessed by 32 bit processes. You can run "odbcad32" or look at the ODBC control panel to see that the driver is present)</p>\n\n<p>While I don\'t see the code with the connection string in your code snippet, I am not aware of any noncommercial Access JDBC drivers for Java, only jdbc->odbc bridging and relying on Windows to have the Access (*.mdb) driver. Microsoft no longer supports this driver and has no plans to port it to 64bit, so infrastructure wise it is something to think about.</p>\n'}, {'answer_id': 67681, 'author': 'David-W-Fenton', 'author_id': 9787, 'author_profile': 'https://Stackoverflow.com/users/9787', 'pm_score': 0, 'selected': False, 'text': "<p>Question to Joshua McKinnon:</p>\n\n<p>Can you provide a citation about MS's plans to never introduce 64-bit ODBC drivers for Jet? This sounds reasonable, so I'm not doubting you at all, I would just like to know if you have a source for it that you can point to.</p>\n\n<p>Surely MS <em>is</em> providing access to Jet on 64-bit systems through OLEDB, though, right? That doesn't help with JDBC, but certainly provides a method to use Jet data (they have to provide something, since Jet 4 is part of the OS, as it is used as the data store for Active Directory, and has been used thus since Windows 2000).</p>\n"}, {'answer_id': 104028, 'author': 'Chris OC', 'author_id': 11041, 'author_profile': 'https://Stackoverflow.com/users/11041', 'pm_score': 1, 'selected': False, 'text': '<p>@david.w.fenton.myopenid.com:  "Can you provide a citation about MS\'s plans to never introduce 64-bit ODBC drivers for Jet?"</p>\n\n<p>David, I found a post on Microsoft\'s Connect Feedback about that.</p>\n\n<p><a href="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=125117" rel="nofollow noreferrer">http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=125117</a></p>\n\n<p>"At the moment there are no plans to ship a 64-bit version of JET driver by Office team. We may considere alternate options and will update you when we have a concrete plan."</p>\n\n<p>Thanks,\nSSIS team.\n Posted by Microsoft on 10/3/2007 at 9:47 PM</p>\n\n<p>There\'s been no update from Microsoft in that feedback thread.</p>\n'}]
['https://Stackoverflow.com/questions/30696', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2786/']