2014-12-14 4 views

답변

0

은 (코드로이 부분에 대한 정확히 동일합니다.)

당신은 이러한 스레드에서 코드의 아이디어를 얻을 수 있습니다. 여기 Java not connecting to MS Access database using Eclipse

How to connect to Access .mdb database from 64-bit Java?

는 튜토리얼을 살펴

http://www.codeproject.com/Articles/35018/Access-MS-Access-Databases-from-Java
또는 http://www.herongyang.com/JDBC/JDBC-ODBC-MS-Access-Connection.html

및 @Marc Estadillo으로
드라이버를 잊지 마세요 말했다 줄입니다.

0
Connection connection = null; 
Statement stmt = null; 
ResultSet rs = null; 
String mySql = "SELECT ..."; // Put your query here. 

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
try 
{ 
    // Arguments 2 and 3 are name and password if required 
    connection = DriverManager.getConnection("jdbc:odbc:myDriver", "", ""); 
    stmt = connection.createStatement(); 
    rs = stmt.executeQuery(mySql);  
    while (rs.next()) { 
    // do stuff with ResultSet 
    } 
} 
catch (SQLException sqle) 
{ 
    ... 
} 
catch (Exception e) 
{ 
    ... 
} 
finally 
{ 
    if (null != rs) 
    { 
     try 
     { 
      rs.close(); 
     } 
     catch (Exception e) 
     { 
      ... 
     } 
     finally 
     { 
      rs = null; 
     } 
    } 

    if (null != stmt) 
    { 
     try 
     { 
      stmt.close(); 
     } 
     catch (Exception e) 
     { 
      ... 
     } 
     finally 
     { 
      rs = null; 
     } 
    } 

    if (null != connection) 
    { 
     try 
     { 
      connection.close(); 
     } 
     catch (Exception e) 
     { 
      ... 
     } 
     finally 
     { 
      rs = null; 
     } 
    } 
} 
+0

이 코드가 질문에 올바르게 대답하는 방법을 설명 할 수 있습니다. – rfornal

관련 문제