标题:[原创]Servlet连接数据库失败,请帮帮忙怎么回事
只看楼主
leifei333
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-1-30
 问题点数:0 回复次数:3 
[原创]Servlet连接数据库失败,请帮帮忙怎么回事

package number;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;

public class Servlet1 extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String name=request.getParameter("name");
String paw=request.getParameter("paw");
String name1;
String paw1;
boolean fags=false;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载桥驱动
}catch(ClassNotFoundException e){
System.out.println("错误");
}
try{

String url="jdbc:odbc:text";
Connection conn=DriverManager.getConnection(url,"sa","");
Statement s=conn.createStatement();
ResultSet rs=s.executeQuery("select * from table where name='"+name+"'and '"+paw+"'");//从这个地方好象有错
if(rs.next()){
name1=rs.getString(1);
paw1=rs.getString(2);
if(name1!=null&&paw1!=null&&name1==name&&paw1==paw){
fags=true;
}
}
else
{
out.print("登陆失败");
}
}catch(SQLException ex){
out.print("连接失败");
}

out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
if(fags){
out.println("<p>欢迎您登陆</p>"+name);
}
out.println("</body>");
out.println("</html>");
out.close();
}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}

//Clean up resources
public void destroy() {
}
}

搜索更多相关主题的帖子: 数据库 import Servlet java public 
2007-01-30 19:13
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
得分:0 
ResultSet rs=s.executeQuery("select * from table where name='"+name+"'and '"+paw+"'");//从这个地方好象有错

当然有错,你这是什么等式?

应该是...where name=name and pwd=pwd

你后面的pwd没有什么可等的啊

可惜不是你,陪我到最后
2007-01-30 19:55
leifei333
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-1-30
得分:0 
ResultSet rs=s.executeQuery("select * from table where name='"+name+"'and paw='"+paw+"'");//从这个地方好象有错
paw加上了也有错啊
郁闷拉
2007-01-30 20:22
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
得分:0 
("select * from table where name='"+name+"'and paw='"+paw+"

table是关键字吧,你可以用它做为表的名字吗?


可惜不是你,陪我到最后
2007-01-30 20:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-118912-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039201 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved