请大家帮个忙(关于java连接SQL)

来源:百度知道 编辑:UC知道 时间:2024/05/28 23:47:11
程序

import java.sql.*;

public class Training {

/**
* @param args
* @throws SQLException
* @throws ClassNotFoundException
* @throws ClassNotFoundException
* @throws
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
try{

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
System.out.println("数据库驱动程序注册成功!");
String strsql="jdbc:mircosoft.jdbc.sqlserver://local:1433;DababaseName=training";
String user="sa";
String pwd="";
Connection conn=DriverManager.getConnection(strsql,user,pwd);
System.out.println("数据连接成功");
}
catch(Exception e)

{
e.printStackTrace();
System.out.println("数据连接失败");
}

}

}

---------

错误

java.lang.ClassNotFoundException: co

不知你用的是不是tomcat,如果是的,把这三个包复制到tomcat 的lib目录下

另外sql2000,如果是xp的话,需要打sp4补丁

一定是三个 jar文件的原因 重新导一下吧

这三个包你要加入环境变量中,要是eclipse开发就直接导入就行,不是的话就在classpath下面加上这个三个包的位置就是!
题外话:注意最后关掉connection,呵呵

jar包没有导入对啊

将local:1433 改为localhost:1433

String strsql="jdbc:mircosoft.jdbc.sqlserver://local:1433;DababaseName=training";
"local",改成localhost试试