myeclipse中用jsp连接sqlserver2008的问题,报错求解
错误提示:
11111
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost:1433; DatabaseName=a_Hss
jsp代码:
<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>成功界面</title>
</head>
<body>
<%!
//public static String driver="com.sqlserver.jdbc.SQLServerDriver";
public static String driver="sun.jdbc.odbc.JdbcOdbcDriver";
//public static String url="jdbc:sqlserver://localhost:1433;DatabaseName=a_Hss";
public static String user="sa";
public static String password="7116105";
%>
<%
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
boolean flag=false;
String name=null;
%>
<%
try{ //JDBC操作会抛出异常,使用try...catch处理
Class.forName(driver);
System.out.println("11111");
//conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433; DatabaseName=a_Hss;user=sa;password=7116105");
conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433; DatabaseName=a_Hss","sa","7116105");
System.out.println("12345");
String sql="select userid from from t1_user where username=? and password=?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,request.getParameter("UserName"));
pstmt.setString(2,request.getParameter("password"));
rs=pstmt.executeQuery();
if (rs.next()){
name = rs.getString(1);
flag = true;
}
}catch(Exception e){
System.out.println(e);
}
finally{
try{
rs.close();
pstmt.close();
conn.close();
}catch(Exception e){}
}
%>
<%
if (flag) {
%>
<jsp:forward page="success.jsp"></jsp:forward>
<%
}else{
%>
<jsp:forward page="failure.jsp"></jsp:forward>
<%
}
%>
</body>
</html>
下载了sqljdbc.jar放到了项目下的web-inf/lib文件中和tomcat 的 lib 文件夹中
------解决方案--------------------右击项目
bulid path
选择bulid config path
add external jars
把sqljdbc.jar加进去
------解决方案--------------------jdbcDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver"
------解决方案--------------------2楼正解
swing的2个有关问题有关问题,求指教