2 qq 32060049 qq_32060049 于 2016.03.31 20:07 提问

jsp中登录验证数据库内内容

<%
request.setCharacterEncoding("utf-8");
String unm = request.getParameter("username");
String psd = request.getParameter("password");

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=dataBase;user=sa;password=sa;";  
    Connection conn = DriverManager.getConnection(connectionUrl);        
    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);  
    String sql="SELECT * FROM dataBase WHERE title = 'unm'";  
    //out.print(sql);          
    ResultSet rs = stmt.executeQuery(sql); 
    if(rs.next()){
        request.getRequestDispatcher("loginSuccess.jsp").forward(request,response);

    }else{
        response.sendRedirect("loginFailure.jsp");
    }

    stmt.close();         
    conn.close();   

%>

    报错说sql语句中database附近有语法错误,望指教!万分感谢!

3个回答

xy_focus
xy_focus   2016.04.01 17:50
已采纳

con=DriverManager.getConnection("jdbc:sqlserver://"+ip+":1433;database="+databaseName,user,password);

devmiao
devmiao   Ds   Rxr 2016.03.31 23:41
xy_focus
xy_focus   2016.04.01 17:48
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!