You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Data整合Oracle遇java.sql.SQLException登录被拒问题求助

Troubleshooting "invalid username/password; logon denied" with Oracle XE, Spring Data & Hibernate

Hey there, let's work through this logon error step by step—since you're using Spring Data, Hibernate, Gradle, and JDK 1.8, I'll tailor the fixes to your specific setup:

1. First, Rule Out Basic Credential Issues

Oracle's case sensitivity can trip you up here, even if you created the user in uppercase:

  • You made JAVAUSER as an uppercase username: If you didn't wrap it in quotes when creating it, Oracle automatically stores it as uppercase (so no problem there). But if you did use quotes, you'll need to match that exact case in your connection config (though it sounds like you didn't, since you specified "uppercase username").
  • For your password PASSWORD: Oracle 11g has SEC_CASE_SENSITIVE_LOGON enabled by default. If you created the password without quotes, it's stored as uppercase—so make sure you're using PASSWORD (all caps) in your config, not lowercase or mixed case.

Quick sanity check: Try logging in directly via SQL*Plus or SQL Developer with this command:

CONNECT JAVAUSER/PASSWORD@localhost:1521/XE;

If this fails, the issue is with the credentials or user account itself, not your Spring/Hibernate setup.

2. Verify Your Spring/Hibernate Connection Config

Double-check your application properties (either application.properties or application.yml) for typos, whitespace, or case mismatches:

Example application.properties:

spring.datasource.url=jdbc:oracle:thin:@localhost:1521:XE
spring.datasource.username=JAVAUSER
spring.datasource.password=PASSWORD
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
# Hibernate config (if needed)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect

Common mistake: Accidental spaces before or after the username/password in the config file—even a single space will cause a logon failure.

3. Confirm Gradle is Pulling the Correct ojdbc6 Dependency

Since you're using a locally installed ojdbc6 (11.0.2.0.2), make sure your build.gradle is correctly referencing it from your local Maven repo:

Example build.gradle dependency block:

dependencies {
    // Oracle JDBC driver from local Maven repo
    implementation 'com.oracle:ojdbc6:11.0.2.0.2'
    // Spring Data & Hibernate dependencies
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.hibernate:hibernate-core'
    // Other project dependencies
}

Run gradle dependencies in your terminal to confirm the ojdbc6 dependency is resolving without errors. A missing or mismatched driver version can sometimes cause authentication-like errors, so it's worth ruling out.

4. Check if the JAVAUSER Account is Locked/Expired

It's possible your user account got locked or expired automatically. Log into Oracle as a privileged user (like SYSTEM or SYS) and run this query:

SELECT username, account_status, lock_date FROM dba_users WHERE username = 'JAVAUSER';

If the status shows LOCKED or EXPIRED, fix it with these commands:

-- Unlock the account if locked
ALTER USER JAVAUSER ACCOUNT UNLOCK;
-- Reset the password (use your desired password here)
ALTER USER JAVAUSER IDENTIFIED BY PASSWORD;

5. Ensure Oracle XE Services are Running

Sometimes a stopped listener or database service can throw misleading authentication errors. Let's check:

  • Windows: Open the Services app (search for services.msc) and make sure OracleXETNSListener and OracleServiceXE are set to "Running".
  • Linux: Run lsnrctl status to check the listener is active, then log into SQL*Plus as sysdba and run SELECT status FROM v$instance; to confirm the database is open.

内容的提问来源于stack exchange,提问作者watchme

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:53:52