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

Java程序连接Oracle 10g时数据库端口号报错问题求助

Troubleshooting Oracle JDBC Port Connection Errors in JCreator

Hey there! Let's work through this port-related error you're hitting when trying to connect your Java program to Oracle 10g. I've dealt with similar headaches before, so here are the key checks and fixes to try:

1. Verify the Oracle Listener is Running

First up, make sure Oracle's listener service is active and listening on port 1521. Here's how to check:

  • Open a command prompt and run:
    lsnrctl status
    
  • Look for output that mentions PORT: 1521 and your database SID amani in the "Services Summary" section.
  • If the listener isn't running, start it with:
    lsnrctl start
    

2. Double-Check Your JDBC URL Format

Your current URL is jdbc:oracle:thin:@localhost:1521:amani—this uses the SID format, which is correct for Oracle 10g, but let's confirm a few details:

  • Is amani definitely your database's SID? You can verify this in the tnsnames.ora file (usually found in Oracle_home\network\admin). Look for an entry like:
    AMANI =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SID_NAME = amani)
        )
      )
    
  • If your setup uses a service name instead of SID (common in some configurations), switch to the service name URL format:
    jdbc:oracle:thin:@//localhost:1521/amani
    

3. Ensure Port 1521 Isn't Blocked or Occupied

  • On Windows, run this command to check if another process is using port 1521:
    netstat -ano | findstr :1521
    
  • If you see an unexpected process ID (PID) listed, you can either terminate that process (if safe) or reconfigure Oracle to use a different port (not ideal, but an option if needed).
  • Also, make sure your local firewall isn't blocking incoming/outgoing traffic on port 1521.

4. Confirm Your JDBC Jar Compatibility

  • You mentioned adding the jar to Oracle's bin and JDK—make sure you're using the correct jar for Oracle 10g, typically ojdbc14.jar (matches JDK 1.4/1.5, which is standard for 10g). Using a newer jar (like ojdbc6/7) might cause compatibility issues.
  • In JCreator, don't just copy the jar to JDK directories—manually add it to your project's classpath: Right-click your project → Properties → Libraries → Add External Jar, then select your ojdbc14.jar file.

5. Test the Connection with SQL*Plus First

Before debugging your Java code, confirm the connection works with SQL*Plus:

  • Run this command in the prompt:
    sqlplus system/a123@localhost:1521:amani
    
  • If SQL*Plus can't connect, the problem is with Oracle's configuration (listener, SID, credentials), not your Java code. Fix that first, then go back to your program.

If you try all these steps and still get errors, share the exact error message you're seeing—it'll help narrow things down even more!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 03:37:06