java 与sqlserver 连接问题(郁闷啊)
java 与sqlserver 连接问题
1,ms jdbc sp3 装了 并己把Lib下的三个.jar文件放到...jre/lib/cmm/ext目录下
2,sqlserver sp4补丁也装了
3,我的系统是XP的
4,classpath和 path变量也设置了
如classpath为.;%C:\Program Files\Java\jdk1.5.0_09\lib;%C:\Program Files\Java\jdk1.5.0_09\lib\tools.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;
5,程序代码为:
import java.sql.*;
public class SQLTest
{
public static void main(String[] args)
{
try
{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String url= "jdbc:microsoft:sqlserver://localhost:1445;DatabaseName=JavaDB ";
String user= "jondy ";
String password= " ";
Connection conn=DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
String sql= "SELECT * FROM Login ";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
System.out.println( "Your frist field is " + rs.getString(1));
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
System.err.println(e);