package demo;
import com.microsoft.*;
import java.sql.*;
import java.net.*;public class Demo
{
//驱动程序常量
private static final String DRIVER_CLASS="com.microsoft.sqlserver.jdbc.SQLServerDriver";
public static void main(String args[])
{
String url="jdbc:microsoft:sqlserver://HotJava:1433;User=sa;Password=123;DatabaseName=pubs";
String qu="select * from titles";
try {
Class.forName(DRIVER_CLASS);
}
catch (ClassNotFoundException ex1)
{
ex1.printStackTrace();
} try {
Connection con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(qu);
while(rs.next())
{
System.out.println(rs.getString(1));
}
rs.close();
stmt.close();
con.close();
} catch (SQLException ex)
{
System.out.println(ex.getMessage());
System.out.println(ex.getNextException());
}
}}
怎么我连接SQL2005,结果显示No suitable drivernull。。什么原因。。我导入包了的,哪有错吗
import com.microsoft.*;
import java.sql.*;
import java.net.*;public class Demo
{
//驱动程序常量
private static final String DRIVER_CLASS="com.microsoft.sqlserver.jdbc.SQLServerDriver";
public static void main(String args[])
{
String url="jdbc:microsoft:sqlserver://HotJava:1433;User=sa;Password=123;DatabaseName=pubs";
String qu="select * from titles";
try {
Class.forName(DRIVER_CLASS);
}
catch (ClassNotFoundException ex1)
{
ex1.printStackTrace();
} try {
Connection con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(qu);
while(rs.next())
{
System.out.println(rs.getString(1));
}
rs.close();
stmt.close();
con.close();
} catch (SQLException ex)
{
System.out.println(ex.getMessage());
System.out.println(ex.getNextException());
}
}}
怎么我连接SQL2005,结果显示No suitable drivernull。。什么原因。。我导入包了的,哪有错吗
Connection c = java.sql.DriverManager.getConnection("jdbc:sqlserver://localhost\\SQLEXPRESS;user=myuser;password=mypass;");
System.out.println("Connected!");
注意2005中URL的写法,驱动也要下新的