JDBC + Access

JDBC + Access

היי. איך אני משלב קישור בג'אווה למסד נתונים של אקסס ? האם אני צריך לשנות הגדרות של odbc או שניתן לבצע הכל דרך הקוד ? אשמח לראות קטע קוד בסיסי - התחברות , שליחת שאילתא והצגת תוצאות. בתודה מראש. אריאל.
 

ליאור ב

New member
הנה חלק...

את ההמשך תבין לבד, אני מקוה...
//absolutPath is the current location. The data base is in a file in the current location. //The name of the data base is "Test.mdb" String location = "jdbc:eek:dbc:MS Access Database;" + "DBQ=" + absolutPath + "DataBase\\test.mdb"; this.dbName = "test.mdb"; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch (java.lang.ClassNotFoundException ex) { Msgs.showError("connectection to dataBase failed with error : " + ex.getMessage()); } try { //session = DriverManager.getConnection("jdbc:eek:dbc:" + dbName); session = DriverManager.getConnection(location, "", ""); // Connect statement = session.createStatement(); } catch (SQLException ex) { Msgs.showError("connectection to dataBase failed with error : " + ex.getMessage()); }​
ליאור.
 

ליאור ב

New member
אהה חשוב מאוד !!!!

Msgs היא מחלקה שאני בניתי ע"מ להפוך את ההודעות למשתמש קלות ובפורמט שלי. showError היא פונקציה סטטית של המחלקה הזאת. תיקון: בסיס הנתונים יושב ב- Folder במיקום הנוכחי ולא ב- file כפי שציינתי. ליאור.
 
למעלה