gpt4 book ai didi

java.sql.SQLRecoverableException : Io error: Invalid number format for port number in ubuntu 错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:08:21 25 4
gpt4 key购买 nike

我正在使用 oracle 11g xe 版本。所以我已经建立了类路径并继续执行该程序,但遇到了这些错误:

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!!

现在我没有使用任何 IDE,也没有在 Windows 中完成。我正在尝试通过 linux 终端连接,所有可用的帮助几乎都适用于 Windows。我为该程序使用的连接字符串是:

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

我使用的代码如下:

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!!");
}
}

最佳答案

我在使用 REST 连接 Oracle 数据库并从中检索数据时遇到了这个问题。

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

这些都是连接 URL 的有效变体,但我最终不得不完全删除端口。

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

我的引用资料Oracle JDBC Connection URL

关于java.sql.SQLRecoverableException : Io error: Invalid number format for port number in ubuntu 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24242715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com