|
周末其他版本没人,所以发到这来了:!!!!!等会请版主转一下了
[php]
package queryBean;
import java.sql.*;
import javax.sql.*;
import java.io.*;
import java.util.Calendar;
public class QueryBean
{
private Connection con = null;
private PreparedStatement pstmt = null;
private ResultSet rs = null;
public QueryBean()
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://192.168.2.160/jxd?user=root&password=&useUnicode=true");
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(InstantiationException e)
{
e.printStackTrace();
}
catch(IllegalAccessException e)
{
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public int demand(String userName,String userPassword)
{
int flag = 0;
try
{
String str = "SELECT username,userlevel FROM userlogin WHERE username=? AND userpassword=?";
pstmt = con.prepareStatement(str);
pstmt.setString(1,userName);
pstmt.setString(2,userPassword);
rs = pstmt.executeQuery();
if(rs.next())
{
flag = Integer.parseInt(rs.getString("userlevel"));
}
pstmt.close();
insert(userName);
rs.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
return flag;
}
private void insert(String userName)
{
try
{
String logusername,logtime;
Calendar nowTime;
logusername = userName;
nowTime = Calendar.getInstance();
int year = nowTime.get(Calendar.YEAR);
int month = nowTime.get(Calendar.MONTH);
int day = nowTime.get(Calendar.DATE);
int hour = nowTime.get(Calendar.HOUR);
int minute = nowTime.get(Calendar.MINUTE);
int second = nowTime.get(Calendar.SECOND);
logtime = String.valueOf(year)+":Y"+String.valueOf(month)+":M"+String.valueOf(day)+""+String.valueOf(hour)+":H"+String.valueOf(minute)+":M"+String.valueOf(second);
pstmt = con.prepareStatement("INSERT INTO log_online VALUES(?,?)");
pstmt.setString(1,logusername);
pstmt.setString(2,logtime);
pstmt.execute();
pstmt.close();
return;
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public String areaReg(String userName,String userPassword)
{
String area = null;
try
{
String str = "SELECT area FROM userlogin WHERE username=? AND userpassword=?";
pstmt = con.prepareStatement(str);
pstmt.setString(1,userName);
pstmt.setString(2,userPassword);
rs = pstmt.executeQuery();
if(rs.next())
{
area = rs.getString("area");
}
rs.close();
pstmt.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
return area;
}
public String areaCity(String userName,String userPassword)
{
String city = null;
try
{
String str = "SELECT area FROM userlogin WHERE username=? AND userpassword=?";
pstmt = con.prepareStatement(str);
pstmt.setString(1,userName);
pstmt.setString(2,userPassword);
rs = pstmt.executeQuery();
if(rs.next())
{
city = rs.getString("city");
}
rs.close();
pstmt.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
return city;
}
}
[/php]
为什么city返回null,而area却可以正常返回,这两个方法没区别吧 |
|