嘗試使用java在Microsoft Access數據庫中插入一些值。Microsoft Access和Java JDBC-ODBC錯誤
我可以但是一個錯誤,
值java.sql.SQLException:[微軟] [ODBC驅動程序管理器]指定的 DSN包含線程的驅動程序和應用 異常之間的結構不匹配「主」 java.lang.NullPointerException
要使用SysWoW64> odbcad32創建數據源,並將其添加到系統DNS的數據源。我這樣說是因爲我已經看到了64位系統出現問題的地方。但它仍然不適合我。
Microsoft Office 32bit。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class AuctionHouseJDBC {
/**
* @param args
*/
public static void main(String[] args) {
String theItem = "Car";
String theClient="Name";
String theMessage="1001";
Connection conn =null; // Create connection object
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Found");
} catch(Exception e) {
System.out.println("Driver Not Found");
System.err.println(e);
}
// connecting to database
try{
String database ="jdbc:odbc:Driver={Microsoft Access Driver (*.accdb)};DBQ=AuctionHouseDatabase.accdb;";
conn = DriverManager.getConnection(database,"","");
System.out.println("Conn Found");
}
catch(SQLException se) {
System.out.println("Conn Not Found");
System.err.println(se);
}
// Create select statement and execute it
try{
/*String insertSQL = "INSERT INTO AuctionHouse VALUES ( "
+"'" +theItem+"', "
+"'" +theClient+"', "
+"'" +theMessage+"')";
*/
Statement stmt = conn.createStatement();
String insertSQL = "Insert into AuctionHouse VALUES ('Item','Name','Price')";
stmt.executeUpdate(insertSQL);
// Retrieve the results
conn.close();
} catch(SQLException se) {
System.out.println("SqlStatment Not Found");
System.err.println(se);
}
}
}
StaceTrace:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
的Microsoft Office 64
伊夫安裝64位版本,現在即時通訊剛開的錯誤[微軟] [ODBC驅動程序管理器]這不是有效的文件名。
http://www.codeproject.com/Articles/35018/Access-MS-Access-Databases-從Java這不是你如何訪問MS Access數據庫,它試圖告訴你。 –
我仍然收到未找到數據源的錯誤。 – user1638362