tomcat6.0报错
jsp连接sql 2008失败
tomcat6.0报错
放了jdbc.jar进web_inf里还是报错,不知道哪里出错了
The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
连接数据库的代码:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student";
String user="sa";
String password="123456";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from student";
ResultSet rs=stmt.executeQuery(sql);
String s="";
while(rs.next()) {%>
您的第一个字段内容为:<%s=rs.getString(1);%>
您的第二个字段内容为:<%s=rs.getString(2);%>
<%}%>
<%out.print("数据库操作成功");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
</html>
连接数据库成功的代码
public void actionPerformed(ActionEvent e) {
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=student";
String username = "sa"; //你的数据库用户名
String pwd ="123456"; //数据库密码
try{
Class.forName(driverName);
Connection conn=DriverManager.getConnection(dbURL,username,pwd);//加载数据库驱动
System.out.println("连接成功");
Statement st = conn.createStatement();
String sql="select * from student";
ResultSet rs = st.executeQuery(sql); //返回查询结果
String s="";
while (rs.next()){
s=rs.getInt(1)+" "+ rs.getInt(2)+" "+rs.getInt(3);
}
txt1.setText(s);
}
catch(Exception e1){
e1.printStackTrace();
System.out.println("连接失败");
}
}
各位大大帮忙改下。。
[解决办法]
错误还是比较明显的,“java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver”
检查下,sql server的jar包 msbase.jar,mssqlserver,msutil.jar ,是否都被引入了?
[解决办法]