简体   繁体   English

java.sql.SQLRecoverableException:错误:Ubuntu中端口号的数字格式无效

[英]java.sql.SQLRecoverableException: Io error: Invalid number format for port number in ubuntu

I am using oracle 11g xe version.So i have established the classpath and went ahead for the program but was facing these errors: 我正在使用oracle 11g xe version.So,我已经建立了类路径并继续执行程序,但遇到了以下错误:

Connecting to database...
    java.sql.SQLRecoverableException: IO Error: Invalid number format for port number
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:478)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:547)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:225)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:29)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:556)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at jdbcdisplay.main(jdbcdisplay.java:24)
    Caused by: oracle.net.ns.NetException: Invalid number format for port number
at oracle.net.resolver.AddrResolution.resolveSimple(AddrResolution.java:497)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:394)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:873)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:258)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1577)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:353)
... 7 more
GoodBye!!

Now i have not used any IDE's nor is it done in windows.I am trying to connect via linux terminal and all the help that is available is almost for Windows. 现在我没有使用过任何IDE,也没有在Windows中完成。我试图通过linux终端进行连接,并且所有可用的帮助几乎都适用于Windows。 The connection string i am using for the program is: 我为程序使用的连接字符串为:

String jdbcUrl="jdbc:oracle:thin:@localhost:1521/XE:orcl";
String user="Sourajyoti";
String password="*******";
conn=DriverManager.getConnection(jdbcUrl,user,password);

The code i am using is as follows: 我使用的代码如下:

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Date;
import java.sql.SQLException;

class jdbcdisplay
{
public static void main(String[] args)
{
    Connection conn=null;

    try
    {
        String driver="oracle.jdbc.driver.OracleDriver";
        Class.forName(driver);

        System.out.println("Connecting to database...");
        String jdbcUrl="jdbc:oracle:thin:@localhost:1521/XE:orcl";
        String user="Sourajyoti";
        String password="******";

        conn=DriverManager.getConnection(jdbcUrl,user,password);
        Statement stmt=conn.createStatement();
        String sql="SELECT ENAME,SALARY,HIREDATE FROM EMP";
        ResultSet rs=stmt.executeQuery(sql);

        while (rs.next())
        {
            String name=rs.getString("ENAME");
            double salary=rs.getDouble(2);
            Date date=rs.getDate("HIREDATE");
            System.out.print("Name: "+name);
            System.out.print("Salary: "+salary);
            System.out.println("Hiredate: "+date);
        }

        rs.close();
        stmt.close();
        conn.close();
    }
    catch(SQLException se)
    {
        se.printStackTrace();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    finally
    {
        try
        {
            if (conn!=null)
                conn.close();
        }
        catch(SQLException se)
        {
            se.printStackTrace();
        }
    }
    System.out.println("GoodBye!!");
}
}

I ran into this issue while using REST to connect and retrieve data from an Oracle DB. 我在使用REST连接和从Oracle DB检索数据时遇到了这个问题。

jdbc:oracle:thin:Herong/TopSecret@localhost:1521:XE
jdbc:oracle:thin:Herong/TopSecret@:1521:XE
jdbc:oracle:thin:Herong/TopSecret@//localhost:1521/XE
jdbc:oracle:thin:Herong/TopSecret@//:1521/XE
jdbc:oracle:thin:Herong/TopSecret@//localhost/XE
jdbc:oracle:thin:Herong/TopSecret@///XE

These are all valid variations on the connection URL, but I eventually had to remove the port altogether. 这些都是连接URL上的有效变体,但最终我不得不完全删除端口。

        "type": "jdbc",
        "name": "test",
        "connection": {
            "driver": "oracle.jdbc.OracleDriver",
            "url": "jdbc:oracle:thin:@//QAORACLE11G.server.local/DatabaseName",
            "user": "QA_DBUSER",
            "password": "QA_DBPASSWORD"
        },

My reference material Oracle JDBC Connection URL 我的参考资料Oracle JDBC Connection URL

Ok the difference was my connection string and i changed it to : 好的,区别是我的连接字符串,我将其更改为:

String jdbcUrl="jdbc:oracle:thin:@localhost:1521:xe";
String user="Sourajyoti";
String password="******";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.sql.SQLRecoverableException:IO错误:生成了NL异常 - java.sql.SQLRecoverableException: IO Error: NL Exception was generated 在IntelliJ中收到错误“ java.sql.SQLRecoverableException:IO错误:套接字读取超时” - got error “java.sql.SQLRecoverableException: IO Error: Socket read timed out” in intellij 数据库连接问题 - 引起:java.sql.SQLRecoverableException:IO 错误:指定的主机未知 - Database connection problem - Caused by: java.sql.SQLRecoverableException: IO Error: Unknown host specified 如何解决 java.sql.SQLRecoverableException:IO 错误:连接超时 - How to resolve java.sql.SQLRecoverableException: IO Error: Connection timed out java.sql.SQLException:Io 异常:端口号的数字格式无效 - java.sql.SQLException: Io exception: Invalid number format for port number java.sql.SQLRecoverableException:IO 错误:文件描述符错误,连接失败 1 毫秒,身份验证失败 0 毫秒 - java.sql.SQLRecoverableException: IO Error: Bad file descriptor, connect lapse 1ms, Authentication lapse 0ms 查询oracle多维数据集时出现java.sql.SqlRecoverableException - java.sql.SqlRecoverableException while querying oracle cube java.sql.SQLRecoverableException:没有更多的数据可以从套接字读取 - java.sql.SQLRecoverableException: No more data to read from socket java.sql.SQLRecoverableException:网络适配器无法建立连接 - java.sql.SQLRecoverableException: The Network Adapter could not establish the connection 无法连接到Oracle数据库:java.sql.SQLRecoverableException - Can not connect to Oracle Database: java.sql.SQLRecoverableException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM