Spring Data整合Oracle遇java.sql.SQLException登录被拒问题求助
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
JAVAUSERas 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 hasSEC_CASE_SENSITIVE_LOGONenabled by default. If you created the password without quotes, it's stored as uppercase—so make sure you're usingPASSWORD(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 sureOracleXETNSListenerandOracleServiceXEare set to "Running". - Linux: Run
lsnrctl statusto check the listener is active, then log into SQL*Plus assysdbaand runSELECT status FROM v$instance;to confirm the database is open.
内容的提问来源于stack exchange,提问作者watchme

