我在做一个网络五子棋对战的手机游戏,但是这中间用到一个用户注册,返回其用户id的操作(数据库端用户id是自动编号的)服务器是用的servlet写的,好象有点错误,因为客户端取得的用户id总是
这个数1752460652,但返回的boolean型值能够取得的
servlet内容是:
public class usercheck extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
//TODO Method stub generated by Lomboz
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//TODO Method stub generated by Lomboz
request.setCharacterEncoding("MS950");
String username=request.getParameter("username");
String password=request.getParameter("password");
DataOutputStream dos=new DataOutputStream(response.getOutputStream());
response.setContentType("text/plain;charset=UTF-8");
boolean check=false;
int userid=0;
String drivername="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=gobang";
String dbusername="sa";
String dbpassword="123";
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try
{
Class.forName(drivername).newInstance();
conn=DriverManager.getConnection(url,dbusername,dbpassword);
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from userInfo where userName="+username+"and password="+ password);
if(rs.next())
{
userid=rs.getInt("UserID");
System.out.println(userid);
check=true;
dos.writeBoolean(check);
dos.writeInt(userid);
dos.flush();
}
else
{
dos.writeBoolean(check);
dos.writeInt(userid);
dos.flush();
}
rs.close();
stmt.close();
conn.close();
}catch(Exception e)
{
}
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//TODO Method stub generated by Lomboz
}
}
大家帮我看看啊
这个数1752460652,但返回的boolean型值能够取得的
servlet内容是:
public class usercheck extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
//TODO Method stub generated by Lomboz
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//TODO Method stub generated by Lomboz
request.setCharacterEncoding("MS950");
String username=request.getParameter("username");
String password=request.getParameter("password");
DataOutputStream dos=new DataOutputStream(response.getOutputStream());
response.setContentType("text/plain;charset=UTF-8");
boolean check=false;
int userid=0;
String drivername="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=gobang";
String dbusername="sa";
String dbpassword="123";
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try
{
Class.forName(drivername).newInstance();
conn=DriverManager.getConnection(url,dbusername,dbpassword);
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from userInfo where userName="+username+"and password="+ password);
if(rs.next())
{
userid=rs.getInt("UserID");
System.out.println(userid);
check=true;
dos.writeBoolean(check);
dos.writeInt(userid);
dos.flush();
}
else
{
dos.writeBoolean(check);
dos.writeInt(userid);
dos.flush();
}
rs.close();
stmt.close();
conn.close();
}catch(Exception e)
{
}
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//TODO Method stub generated by Lomboz
}
}
大家帮我看看啊