I m 试图利用像样的编码与矿石数据库连接:
public static Connection getConnection() throws ClassNotFoundException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Properties env = new Properties();
//env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://192.168.1.1:389/o=myo,dc=mydc,dc=us");
Connection connection = null;
try {
InitialContext context = new InitialContext(env);
DataSource dataSource = (DataSource) context.lookup("jdbc/DataSource");
connection = dataSource.getConnection();
} catch (NamingException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
但它始终不例外:
javax.naming.InvalidNameException: jdbc: [LDAP: error code 34 - invalid DN]; remaining name jdbc/DataSource
哪里,以及怎样才能具体指出:jdbc/DataSource?
I m confused as I was given a working project using codes similar as above but nowhere tells what DataSource is. I m wondering if jdbc/DataSource should be a DN in LDAP, but I find nothing seem relavent in my given ldap data. Sorry if that question is stupid or not make sense, i m new to that all stuff.
感谢!