Ric*_*emp 1 java linux sybase jdbc sqoop
我在建立从 Red Hat Linux 服务器到 Sybase 服务器的 JDBC 连接时遇到困难。我从 SQLException 得到的错误代码只是“JZ00L:登录失败”,后跟“010HA:服务器拒绝了您使用高可用性功能的请求”。我没有请求使用 HA,事实上,为了确定起见,将该属性设置为 false。
我们在这台 Red Hat Linux 服务器上安装了 Sqoop,我们可以创建 Sqoop 作业,从这台 sybase 服务器上连接和查询数据。我在 Sqoop 和我的 Java 代码中使用相同的驱动程序、连接和身份验证信息。
我在互联网上看到了一些关于代码页有时会导致问题的参考资料。但我不知道如何在代码中解决这个问题。
下面是java代码:
import java.sql.*;
import com.sybase.jdbc4.jdbc.SybDriver;
import java.util.Properties;
/**
* A JDBC SELECT (JDBC query) example program.
*/
class Query1 {
public static void main (String[] args) {
try {
SybDriver sd = (SybDriver)Class.forName("com.sybase.jdbc4.jdbc.SybDriver").newInstance();
System.out.println("Driver loaded");
Connection conn = DriverManager.getConnection("jdbc:sybase:Tds:srpsyb25:2025","...","...");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1 AS One");
while ( rs.next() ) {
String col = rs.getString("One");
System.out.println(col);
}
conn.close();
}
catch (SQLException e)
{
for (SQLException current = e; current != null; current = current.getNextException())
{
System.out.println ("=================================================");
System.out.println("SQL exception : " + current.toString());
System.out.println("SQL State : " + current.getSQLState());
System.out.println("Error Code : " + current.getErrorCode());
Throwable t = current.getCause();
while(t != null) {
System.out.println("Cause: " + t);
t = t.getCause();
}
}
System.exit(1);
}
catch (Exception e) {
System.err.println("Unexpected exception! ");
System.err.println(e.getMessage());
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是控制台输出。请注意,我的类路径仅限于该单个驱动程序,因此我相信我正在使用该驱动程序:
$ java -cp /var/lib/sqoop/jconn4.jar:. Query1
Driver loaded
=================================================
SQL exception : java.sql.SQLException: JZ00L: Login failed. Examine the SQLWarnings chained to this exception for the reason(s).
SQL State : JZ00L
Error Code : 0
=================================================
SQL exception : java.sql.SQLWarning: Login failed.
SQL State : 01ZZZ
Error Code : 4002
=================================================
SQL exception : java.sql.SQLWarning: 010HA: The server denied your request to use the high-availability feature. Please reconfigure your database, or do not request a high-availability session.
SQL State : 010HA
Error Code : 0
=================================================
SQL exception : java.sql.SQLWarning: Login failed.
SQL State : 01ZZZ
Error Code : 4002
=================================================
SQL exception : java.sql.SQLWarning: 010HA: The server denied your request to use the high-availability feature. Please reconfigure your database, or do not request a high-availability session.
SQL State : 010HA
Error Code : 0
$
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19803 次 |
| 最近记录: |