困扰了我好几天,用jdbc连接数据库的问题,不知道卡在哪里了,请大伙帮我看看。谢谢,帮我顶一顶,也给分。
zg 2002-11-01 03:46:03 我不是偷懒,我已经查了csdn上很多帖子,能打开的我都看了,还是不行。
我的代码,我是连接informix数据库,本代码唯一的功能就是测试连接。
import java.sql.*;
import java.util.*;
public class conn {
public static void main(String[] args)
{
String url ="jdbc:informix-sqli://10.110.180.1:8002/testdb:informixserver=nmserver3;user=test;password=test";
String testName = "Simple Connection";
Connection conn = null;
System.out.println(">>>" + testName + " test.");
System.out.println("URL = \"" + url + "\"");
try
{
Class.forName("com.informix.jdbc.IfxDriver");
}
catch (Exception e)
{
System.out.println("ERROR: failed to load Informix JDBC driver.");
}
try
{
conn = DriverManager.getConnection(url);
}
catch (SQLException e)
{
System.out.println("ERROR: failed to connect!");
}
try
{
conn.close();
}
catch (SQLException e)
{
System.out.println("ERROR: failed to close the connection!");
}
System.out.println(">>>End of " + testName + " test.");
}
}
每次运行是连接失败。我的url配置都是参照odbc的连接配置的,比如端口号(8002),server名称(nmserver3),用的都和配置odbc的时候一样。url的格式是照驱动的帮助写的。我不知道informix数控库还要装什么东西才能被jdbc连接上吗?我的代码有毛病吗?请大家帮我看看,我已经被折磨了两天了,帮帮忙,帮我顶一下,我也很感激。谢谢。