MyEclipse6.0连接SQL2000和2005
步骤:
1. 下载Microsoft SQL Server 2000 Driver for JDBC这个,并在MyEclipse 6.0中添加了引用
2. 加环境变量
CLASSPATH值%JAVA_HOME%in;
JAVA_HOME值C:Program FilesJavajdk1.6.0_02
修改增加path值%JAVA_HOME%in;
3. 安装SQL 2000的SP3补丁
4. 在命令下测试telnet localhost 1433正常
代码如:
import java.sql.*;
public class HelloWorld {
private static String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
private static String dbURL = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
private static Connection dbConn = null;
public static void main(String [] args)
{
try
{
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL,"sa","");
Statement sql = dbConn.createStatement();
ResultSet set = sql.executeQuery("select * from jobs");
while(set.next())
{
System.out.println(set.getString("job_id")+" "+
set.getString("job_desc"));
}
System.out.println("连接成功!");
dbConn.close();
} catch (ClassNotFoundException e)
{
e.printStackTrace();
} catch (SQLException e)
{
e.printStackTrace();
}
}
}
测试成功!
连2005
1. 下载sqljdbc_1.1.1501.101_chs.exe并引入
2. 更改端口为5125(用360查出的)
import java.sql.*;
public class DbConnect {
private static String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static String dbURL = "jdbc:sqlserver://localhost:5125; DatabaseName=master";
private static Connection dbConn = null;
public static void main(String[] args) {
try
{
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL,"sa","000000");
Statement sql = dbConn.createStatement();
ResultSet set = sql.executeQuery("SELECT * FROM spt_values");
while(set.next())
{
//System.out.println(set.getString("name")+" "+
//set.getString("number"));
System.out.println(set.getString(1));
}
System.out.println("连接成功!");
dbConn.close();
} catch (ClassNotFoundException e)
{
e.printStackTrace();
} catch (SQLException e)
{
e.printStackTrace();
}
}
}
- 默认分类(20)
- J2EE(25)
- Java(56)
- PHP(55)
- SEO(10)
- 网页设计(20)
- 网站建设(37)
- 数据库(7)
- JavaScript(17)
- JQuery(6)
- MySQL(20)
- SQL Server(6)
- Access(1)
- Oracle(6)
- office(6)
- Dreamweaver(4)
- Photoshop(12)
- Flash(9)
- Fireworks(13)
- CSS(14)
- HTML(4)
- .NET(7)
- ASP(2)
- DB2(1)
- Ajax(2)
- Linux(12)
- Struts(7)
- Hibernate(8)
- Spring(2)
- Jsp(22)
- Asp(8)
- C#(3)
- C++(1)
- 网络安全(5)
- 软件工程(7)
- XML(1)
- English(2)
- 计算机等级考试(2)
- 计算机病毒(4)
- 个人日志(76)
- 互联网(15)
- ActionScript(10)
- Android(3)
- 数据结构与算法(1)
- 游戏策略(3)
- 美文翻译(2)
- 编程开发(19)
- 计算机应用(4)
- 计算机(10)
- Unity3d(6)
- 其他(1)
- egret(1)