1 package nmp.dbms.win32.MSAccess; 2 3 import java.io.*; 4 import java.sql.*; 5 import nmp.dbms.*; 6 import nmp.dbms.JDBC.*; 7 import nmp.dbms.util.*; 8 9 /*** 10 * This interface defines the methods that must be implemented to allow coobjects 11 * in some volume to access a RDBMS transparently 12 * (under construction) 13 * This interface represents a very early specification 14 */ 15 public class DBIntMSAccess 16 // implements DBInterface, java.io.Serializable 17 { 18 /*** 19 * Gets the handle to the database associated with the given coobject 20 * @param oid Handle for the coobject 21 * @param dbName Name (prefix) of the database 22 * @param type Comonent of the coobject 23 * @param user User name that should be used to access to the database 24 * @param passwd Password that should be used to access to the database 25 * @return Returns an handle to the database. This handle should be saved by the 26 * coobject 27 */ 28 /* public DBHandle getNewDBHandle( ObjectHandle oid, String dbName, int type, String user, String passwd) 29 throws ObjCompNotFoundException { 30 try { 31 int i = 0; 32 String url = ""; 33 34 do { 35 url = dbName + DSCSConstant.llSeparator + i++ + DSCSConstant.llSeparator + type + ".mdb"; 36 } while( existsDB( url, user, passwd)); 37 38 if( ! ( ODBCUtil.SQLConfigDataSource( ODBCUtil.ODBC_ADD_DSN, "Microsoft Access Driver (*.mdb)", 39 "CREATE_DB=" + oid.underlineDBFile( type) + "") 40 && ODBCUtil.SQLConfigDataSource( ODBCUtil.ODBC_ADD_DSN, "Microsoft Access Driver (*.mdb)", 41 "DSN=" + url + ";DBQ=" + oid.underlineDBFile( type) + ";USER=" + user + ";PASSWD=" + passwd +";\0"))) 42 throw new ObjCompNotFoundException( "ODBC not initialized"); 43 return new JDBCHandle( "sun.jdbc.odbc.JdbcOdbcDriver", url, "jdbc:odbc:" + url, user, passwd); 44 } catch( Throwable ex) { 45 DSCSUtil.log( ex); 46 throw new ObjCompNotFoundException(); 47 } 48 } 49 50 51 /** 52 * Gets the handle to the database associated with the given coobject 53 * @param oid Handle for the coobject 54 * @param dbName Name (prefix) of the database 55 * @param type Comonent of the coobject 56 * @param user User name that should be used to access to the database 57 * @param passwd Password that should be used to access to the database 58 * @return Returns an handle to the database. This handle should be saved by the 59 * coobject 60 */ 61 /* public DBHandle getDBHandle( ObjectHandle oid, String dbName, int type, String user, String passwd) 62 throws ObjCompNotFoundException { 63 try { 64 return new JDBCHandle( "sun.jdbc.odbc.JdbcOdbcDriver", dbName, "jdbc:odbc:" + dbName, user, passwd); 65 } catch( Throwable ex) { 66 DSCSUtil.log( ex); 67 throw new ObjCompNotFoundException(); 68 } 69 } 70 71 72 73 /** 74 * Returns true if the database with the associated url exists 75 * UGLY ! -> TO BE CHANGED 76 * @param dbName Source name of the database 77 * @param user Username 78 * @param passwd Password 79 */ 80 /* public boolean existsDB( String dbName, String user, String passwd) { 81 try { 82 new JDBCHandle( "sun.jdbc.odbc.JdbcOdbcDriver", dbName, "jdbc:odbc:" + dbName, user, passwd); 83 return true; 84 } catch( Exception e) { 85 return false; 86 } 87 } 88 89 /** 90 * Removes the database associated with the given coobject 91 * @param oid Handle for the coobject 92 * @param dbName Name (prefix) of the database 93 * @param type Comonent of the coobject 94 * @param user User name that should be used to access to the database 95 * @param passwd Password that should be used to access to the database 96 * @return Returns true if the database has been successfully removed. 97 */ 98 /* public boolean remDBHandle( ObjectHandle oid, String dbName, int type, String user, String passwd) 99 throws ObjCompNotFoundException { 100 try { 101 File f = new File( oid.underlineDBFile( type)); 102 f.delete(); 103 return ODBCUtil.SQLConfigDataSource( ODBCUtil.ODBC_REMOVE_DSN, "Microsoft Access Driver (*.mdb)", 104 "DSN=" + dbName + "\0"); 105 } catch( Throwable ex) { 106 DSCSUtil.log( ex); 107 return false; 108 } 109 } 110 */ 111 } 112

This page was automatically generated by Maven