public class test1 {
PreparedStatement per = null;
Connection con = null;
ResultSet res = null;
test1(){
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection
("jdbc:microsoft:sqlserver://127.0.0.1:1433;DateabaseNam=test1","李白","xk53fdab");
per = con.prepareStatement("select * from emp");
res = per.executeQuery();
while(res.next()){
String name = res.getString("ename");
int sal = res.getInt("sal");
System.out.println(name + " " + sal);
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
new test1();
}
}/code]
这是代码
这是异常
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://127.0.0.1:1433;DateabaseNam=test1
at java.sql.DriverManager.getConnection(DriverManager.java:604)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
at test1.<init>(test1.java:15)
at test1.main(test1.java:34)
这是我的jar包 sqljdbc_3.0的