java连数据库出错

来源:百度知道 编辑:UC知道 时间:2024/06/03 20:30:34
原代码:
import java.sql.SQLException;

/**
*
*/

/**
* @author aqi
*@version 0.1
*/
public class JDBCHello {

/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch (ClassNotFoundException e) {
e.printStackTrace();

}
java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabastName=test","sa","");
java.sql.Statement sql = conn.createStatement();
java.sql.ResultSet rs=sql.executeQuery("select * from user");
while(rs.next()) {
System.out.println(rs.getInt(1));
System.out.println(rs.getString("username"));
System.out

驱动有问题了.有没有打过补丁

("jdbc:microsoft:sqlserver://localhost:1433;DatabastName=test","sa","");
应该是DatabaseName=test吧
你改什么了 是base 不是bast

("jdbc:microsoft:sqlserver://localhost:1433;DatabastName=test","sa","");

可能是数据库连接出错
这里你的数据库登陆密码是为空吗???---"sa","");