我无法连接到任何地方的16位数据库

时间:2018-02-15 19:16:41

标签: java database eclipse database-connection sqlanywhere

我一直尝试在任何地方连接sql(第16节),但我得到的是

(java.sql.SQLException: [Sybase][JDBC Driver][SQL Anywhere]Database server not found) error.

这是我的代码:

public class DBConnection {

private LoginGUI loginGUI;
protected Connection conn;  

String dbName = "CPO";

public DBConnection(LoginGUI loginGUI) {
    this.loginGUI=loginGUI;

    String user = loginGUI.getUsernameStr();
    String passwd = loginGUI.getPasswordStr();

    String dbUrl = "jdbc:sqlanywhere:uid=" + user + ";pwd=" + passwd + ";eng=demo"; 

    try {
        conn = DriverManager.getConnection (dbUrl);
        loginGUI.getLoginFrame().setVisible(false);
        GUI gui = new GUI();
    } catch (SQLException e) {
        System.err.println("Can't connect to database");
        System.err.println("(" + e + ")\n");

    }       
}


public Connection connection() {

    return this.conn;
}


}

1 个答案:

答案 0 :(得分:0)

如果您正在使用SQL Anywhere 16的JDBC驱动程序,则需要将其更改为以下内容:

x

请参阅SAP's documentation

或者,您也可以查看支持SQL Anywhere的开源JDBC驱动程序jtds。在这种情况下,连接字符串将是

jdbc:sybase:Tds:[server-ip]:[port]/[dbName]