我习惯于将 Oracle 与 Spring 和 DBCP 连接起来。
<bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521/ORCL" />
<property name="username" value="PMSYSDB" />
<property name="password" value="********" />
</bean>
但我得到:Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (IO Error: The Network Adapter could not establish the connection)
我可以通过 SQLDeveloper 使用以下属性进行连接:
Hostname: localhost
Port : 1521
SID : ORCL
username: PMSYSDB
password:
所以我的数据库已启动并正在运行...防火墙已关闭...数据库和tomcat在同一台机器上...
认为这并不重要,但我将数据源与 Spring Security 一起使用:
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="
select username, password, enabled
from users where username=?"
authorities-by-username-query="
select u.username, ur.authority from users u, user_roles ur
where u.user_id = ur.user_id and u.username =? "
/>
</authentication-provider>
</authentication-manager>