日期:2014-05-17  浏览次数:20874 次

求帮助 myeclipse9.0连接ms sql server2008的问题 怎么解决啊
An error occurred at line: 31 in the jsp file: /exa4.1.jsp
Connection cannot be resolved to a type
28: String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
29: String user="sa";
30: String password="database";
31: Connection conn= DriverManager.getConnection(url,user,password);
32: Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATATABLE);
33: String sql="select * from student";
34: ResultSet rs=stmt.executeQuery(sql);


------解决方案--------------------
你没有装载驱动类
数据库的驱动类都没有装载,获取不到连接
Class.forName("driverclass").newInstance();
------解决方案--------------------
Connection 它的包你没有导入进来吧。
要不你这样吧。把Connection 改为:java.sql.Connection 吧。
------解决方案--------------------
public class DBConn {
public final static String DRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
public final static String URL="jdbc:sqlserver://localhost:1433;databaseName=testDB";
public final static String username="sa";
public final static String password="123";

public static Connection getCon(){
Connection con=null;
try {
Class.forName(DRIVER);
try {
con=DriverManager.getConnection(URL,username,password);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}

没在JSP页面直接连接数据库操作,一般我是写个DBConn连接类,然后部署Tomcat,运行就OK啦~~~