package util;
import DB.DatabaseOperater;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class userUtil
{
Connection con = null;
PreparedStatement sta = null;
ResultSet rs = null;
public String getUserName(String Uid)
{
String name = "";
try
{
if(con == null)
{
DatabaseOperater dbo = new DatabaseOperater();
dbo.getSqlConnection();
}
sta = con.prepareStatement("select name from UserInfo where uid = ?");
sta.setString(1,Uid);
rs = sta.executeQuery();
while(rs.next())
{
name = rs.getString(1);
}
con.close();
}
catch(Exception ex)
{
System.err.println(ex.getMessage());
}
finally
{
return name;
}
}
}
这行代码我实在找不出问题在哪里 确定Uid的值完全可以取到 一切正常 就是访问数据库查不出东西 ResultSet一直没有值 sql语句在sql里看也是正常的
------解决方案--------------------
if(con == null)
{
DatabaseOperater dbo = new DatabaseOperater();
dbo.getSqlConnection();
}
改为: if(con == null)
{
DatabaseOperater dbo = new DatabaseOperater();