用jdbc连接sybase,连接不上
我是这么写的:
import java.sql.*;
import java.util.*;
public class testJDBC {
public static void main(String[] args) throws Exception {
Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();
String url = "jdbc:sybase:Tds:192.168.0.43:4100/sql";
Properties sysProps = System.getProperties();
sysProps.put("user", "321321");
sysProps.put("password", "123123");
Connection conn = DriverManager.getConnection(url, sysProps);
}
}
期中connection那句话一直报错:
Exception in thread "main" java.sql.SQLException: JZ006: Caught IOException: java.net.ConnectException: Connection timed out: connect
at com.sybase.jdbc3.jdbc.ErrorMessage.raiseError(Unknown Source)
at com.sybase.jdbc3.jdbc.ErrorMessage.raiseErrorCheckDead(Unknown Source)
at com.sybase.jdbc3.tds.Tds.a(Unknown Source)
at com.sybase.jdbc3.tds.Tds.a(Unknown Source)
at com.sybase.jdbc3.tds.Tds.login(Unknown Source)
at com.sybase.jdbc3.jdbc.SybConnection.a(Unknown Source)
at com.sybase.jdbc3.jdbc.SybConnection.handleHAFailover(Unknown Source)
at com.sybase.jdbc3.jdbc.SybConnection.<init>(Unknown Source)
at com.sybase.jdbc3.jdbc.SybConnection.<init>(Unknown Source)
at com.sybase.jdbc3.jdbc.SybDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at testJDBC.main(testJDBC.java:15)
我用的是sybase,建立的数据库名字叫sql.db,位置是:G:\sybase\data\sql.db,我的帐号叫321321,密码是123123,我直接打开sybase,然后连接,输入帐号密码可以连进去,但是这样却连不上,请问我哪里有问题?
[解决办法]
String url = "jdbc:sybase:Tds:192.168.0.43:4100/sql";
你后面没有指定数据库名
这样子:
String url = "jdbc:sybase:Tds:192.168.0.43:4100/sql;databaseName=xxxx";
[解决办法]
你用MyEclipse试试,我老师说,eclipse有点问题,需要连接数据库的项目,最好是在MyEclipse中写啊,