Scala连接Oracle数据库报错求助:ORA-01034等错误
Hey there, let's work through this connection error you're facing. That ORA-01034: ORACLE not available paired with ORA-27101: shared memory realm does not exist usually signals issues with the Oracle database instance itself or your connection setup. Here's how to troubleshoot step by step:
1. Verify the Oracle Database Instance is Running
The shared memory error tells us the database process likely isn't active on the server. On your Linux machine:
- Check for the database instance's monitoring process with:
You should see a process namedps -ef | grep pmonora_pmon_dfdev(matching yourdfdevinstance). If not, the instance is down. - To start it, log into SQL*Plus as a sysdba:
Then run:sqlplus / as sysdba
If you hit mount issues, try:startup;startup mount; alter database open;
2. Double-Check Your JDBC URL Format
Your current URL uses the service name syntax (@db-dfdev:1521/dfdev), but we need to confirm this is correct:
- On the database server, run
lsnrctl statusand look for the "Services Summary" section. Ensuredfdevis listed as a service name. - If you intended to use the SID instead, adjust the URL to use a colon separator:
ods.setURL("jdbc:oracle:thin:@db-dfdev:1521:dfdev")
3. Confirm Network Connectivity
Make sure your Scala machine can reach the Oracle server:
- Test basic connectivity with
ping db-dfdev— if this fails, check your DNS settings or add an entry in/etc/hostsfor the server. - Test the database port with
telnet db-dfdev 1521. If the connection is refused:- Check the server's firewall rules to ensure port 1521 is open.
- Verify the Oracle listener is running with
lsnrctl status; start it if needed withlsnrctl start.
4. Validate Oracle JDBC Driver Setup
Ensure your Scala project has the correct Oracle JDBC driver dependency, matching your database version. For sbt projects, add this to your build.sbt:
libraryDependencies += "com.oracle.database.jdbc" % "ojdbc8" % "21.13.0.0"
Quick Pre-Code Test
Before debugging your Scala code further, test the connection directly with SQL*Plus from your machine (or the server) to rule out database-side issues:
sqlplus TM_ODS/odstm@db-dfdev:1521/dfdev
If this fails, fix the database/network issues first before revisiting your Scala code.
内容的提问来源于stack exchange,提问作者Nagendra Palla

