OK I have what appears to be a strange thing. I have an app that is using 2 databases. One is actually Novel's jdbc ldap driver which I use to connect to Edir. That works fine. The second connects to an access database. I am using a jdbc type 4 access driver. Ok the class which connects to access extends teh JdbcDaoSupport class and has a datasource injected into it. The problem is even though the datasource is set and I have set the driverClassName to teh access type 4 driver I am getting an error saying [Novell][LDAP JDBC Driver] Invalid URL and/or properties which means it is trying to use the Novell jdbc driver. See code below. I don't think it matters but this is a web service.
Spring BeansDataBaseAccessImplCode:<bean id="accessDS" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>com.hxtt.sql.HxttConnectionPoolDataSource</value> </property> <property name="url"> <value>C:\Documents and Settings\Jtesser\Desktop\NDS\batch\NDS2002.mdb</value> </property> <property name="username"> <value>xxxx</value> </property> <property name="password"> <value>xxxxx</value> </property> </bean> <bean id="database" class="edu.bju.ws.ldapToDBSync.DataBaseAccessImpl"> <property name="dataSource"> <ref bean="accessDS"/> </property> </bean> <bean id="query" class="edu.bju.ws.ldap.edir.jdbc.Query"> <property name="baseDN"> <value>xxxxx</value> </property> <property name="server"> <value>xxxxxx</value> </property> <property name="query"> <value>SELECT cn_s, fullName, mail, ou,telephoneNumber, NDS_Name, NDS_FullName, nGWPostOffice FROM inetOrgPerson</value> </property> <property name="user"> <value>xxxxxx</value> </property> <property name="password"> <value>xxxxx</value> </property> </bean> <bean id="ldap" class="edu.bju.ws.ldapToDBSync.LDAPEdirJDBCImpl"> <property name="query"> <ref bean="query"/> </property> </bean> <bean id="ldapSync" class="edu.bju.ws.ldap.LdapSync"> <property name="dataBase"> <ref bean="database"/> </property> <property name="ldap"> <ref bean="ldap"/> </property> </bean>
The class that calls all these guysCode:public class DataBaseAccessImpl extends JdbcDaoSupport implements DataBase { static Logger log = Logger.getLogger(DataBaseAccessImpl.class); public int syncLDAPUsers(ArrayList<LDAPPerson> ldapPeople) { JdbcTemplate tem = getJdbcTemplate(); int insertedRows = 0; for (LDAPPerson person : ldapPeople) { try{ tem.execute("insert into NDS_INFO(PERSON_ID, COMMON_NAME, FULL_NAME, EMAIL_ID, NDS_NAME, POST_OFFICE, DEPARTMENT_ID, PHONE_NUMB) values(" + person.getBjuID() + "," + person.getUserName() + "," + person.getFullName() + "," + person.getEmail() + "," + person.getLdapName() + "," + person.getPostOffice() + "," + person.getDepartment() + "," + person.getPhoneNumber()); insertedRows++; } catch (Exception e) { log.error("Error while inserting row into access " + e.toString()); } } return insertedRows; } }
I will include the Query and LDAPEdirJDBCImpl but I do not think they are the problem because they work fineCode:@WebService(serviceName = "LdapSync", endpointInterface = "edu.bju.shared.ws.ldap.LdapToDBSync") public class LdapSync implements LdapToDBSync { private DataBase dataBase; private LDAP ldap; public int sync() { ArrayList<LDAPPerson> people = ldap.loadLdapUsers(); return dataBase.syncLDAPUsers(people); } /** * @return Returns the dataBase. */ public DataBase getDataBase() { return dataBase; } /** * @param dataBase The dataBase to set. */ public void setDataBase(DataBase dataBase) { this.dataBase = dataBase; } /** * @return Returns the ldap. */ public LDAP getLdap() { return ldap; } /** * @param ldap The ldap to set. */ public void setLdap(LDAP ldap) { this.ldap = ldap; } }
Code:public class Query { private String query; private String server; private String user; private String password; private String baseDN; private String url; static Logger log = Logger.getLogger(Query.class); public ResultSet executeQuery() { ResultSet result = null; try { //load the driver System.out.println("loading driver class"); Class.forName("com.novell.sql.LDAPDriver"); System.out.println("loading driver class"); //get a driver instance Driver driver = DriverManager.getDriver("jdbc:ldap"); url = "jdbc:ldap://" + server + ";user=" + user + ";password=" + password + ";baseDN=" + baseDN + ";useCleartext=true"; Connection conn = driver.connect(url, null); Statement statement = conn.createStatement(); result = statement.executeQuery(query); conn.close(); } catch (SQLException e) { log.error("Unable to execute SQL query against eDir /r/n" + e.toString(),e); } catch (ClassNotFoundException e) { log.error( "Could not find the Driver Class: com.novell.sql.LDAPDriver"); } catch(java.lang.NullPointerException e) { log.error(e.toString(), e); } return result; } /** * @return Returns the baseDN. */ public String getBaseDN() { return baseDN; } /** * @param baseDN The baseDN to set. */ public void setBaseDN(String baseDN) { this.baseDN = baseDN; } /** * @return Returns the password. */ public String getPassword() { return password; } /** * @param password The password to set. */ public void setPassword(String password) { this.password = password; } /** * @return Returns the query. */ public String getQuery() { return query; } /** * @param query The query to set. */ public void setQuery(String query) { this.query = query; } /** * @return Returns the server. */ public String getServer() { return server; } /** * @param server The server to set. */ public void setServer(String server) { this.server = server; } /** * @return Returns the url. */ public String getUrl() { return url; } /** * @param url The url to set. */ public void setUrl(String url) { this.url = url; } /** * @return Returns the user. */ public String getUser() { return user; } /** * @param user The user to set. */ public void setUser(String user) { this.user = user; } }Code:public class LDAPEdirJDBCImpl implements LDAP { private Query query; static Logger log = Logger.getLogger(Query.class); public ArrayList<LDAPPerson> loadLdapUsers() { ResultSet rs = query.executeQuery(); ArrayList<LDAPPerson> ldapPeople = new ArrayList<LDAPPerson>(); try { while(rs.next()){ int bjuID = cleanUpCN(rs.getString(0)); if(bjuID != 0){ LDAPPerson ldapPerson = new LDAPPerson(); ldapPerson.setBjuID(bjuID); ldapPerson.setFullName(rs.getString(1)); ldapPerson.setEmail(rs.getString(2)); ldapPerson.setDepartment(rs.getString(3)); ldapPerson.setPhoneNumber(rs.getString(4)); ldapPerson.setUserName(cleanupUserName(rs.getString(5))); ldapPerson.setLdapName(cleanupLDAPName(rs.getString(6))); ldapPerson.setPostOffice(cleanupPostOfficeName(rs.getString(7))); ldapPeople.add(ldapPerson); } } } catch (Exception e) { log.error("An error occured while loading the results from eDir " + e.toString(), e); } return ldapPeople; } private int cleanUpCN(String cn){ int bjuID = 0; DelimitedString ds = new DelimitedString(cn, ","); for(int idx=0;idx<ds.getColumnCount();idx++){ try{ bjuID = ds.getColumnIntValue(idx); } catch (Exception e) { log.info("Value in cn is not an integer"); } } return bjuID; } private String cleanupUserName(String userName){ String cleanedUserName = null; if(userName == null){ userName = ""; } cleanedUserName = userName.substring(userName.indexOf("=")+1); return cleanedUserName; } private String cleanupPostOfficeName(String po){ StringBuffer cleanedPO = new StringBuffer(); DelimitedString ds = new DelimitedString(po,","); for(int idx=0;idx<ds.getColumnCount();idx++){ String col = ds.getColumnStringValue((ds.getColumnCount()- 1) - idx); cleanedPO.append(col.substring(col.indexOf("=")+1)); if(ds.getColumnCount()-idx!=0){ cleanedPO.append("\\"); } } return cleanedPO.toString(); } private String cleanupLDAPName(String ldapName){ StringBuffer cleanedName = new StringBuffer(); DelimitedString ds = new DelimitedString(ldapName,","); for(int idx =0;idx<ds.getColumnCount();idx++){ String col = ds.getColumnStringValue((ds.getColumnCount()-1) - idx); cleanedName.append(col.substring(col.indexOf("n")+2)); if(ds.getColumnCount()-idx!=0){ cleanedName.append("\\"); } } return cleanedName.toString(); } /** * @return Returns the query. */ public Query getQuery() { return query; } /** * @param query The query to set. */ public void setQuery(Query query) { this.query = query; } }


Reply With Quote