怎样将SQL server 2000与MyEclipse 7.1连接在一起

纯新手,拜托详细些
2024-12-29 10:17:52
推荐回答(2个)
回答1:

这是我写的一个oracle数据库连接,你把里面的东西改成2000的就行了,里面的里连接方式是使用集群
public class DBconn {
//private static Logger log = Logger.getLogger(DBconn.class.getClass());
private static Connection conn;
private static String url = "jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL= TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = xxxx))" +
"(ADDRESS =(PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = xxxx)))" +
"(CONNECT_DATA =(SERVICE_NAME = xxxx)))";

private static String username = "xxxx";
private static String password = "xxxx";
private static DBconn dbConn1 = new DBconn();

private DBconn()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url,username,password);
}
catch (Exception sex)
{
System.out.println(sex);
}
}

public static Connection getConnection()
{
return conn;
}

public static DBconn getInstance()
{
return dbConn1;
}

public Integer insert(String sql)
{
Integer result = 0;

try {
Statement statement = conn.createStatement();
result = statement.executeUpdate(sql);
}
catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}

return result;
}

public ResultSet query(String sql)
{
try
{
Statement statement = conn.createStatement();
return statement.executeQuery(sql);
}
catch (Exception ex)
{
ex.printStackTrace();
}
return null;
}

}

回答2:

sqlserver2000的驱动吗,可以添加用户库,或直接在你的项目lib下把驱动包考过去,也可以用持久层框架来做