userinfomodule.java

来自「文件共享虚拟社区,可以实现上传下载聊天等多种信息交互.」· Java 代码 · 共 100 行

JAVA
100
字号
/*
 * Created on 2005-9-8
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package fsc.server.modules;

/**
 * @author chenhao
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

import java.sql.*;
import java.util.Date;

import fsc.models.*;
import fsc.models.exceptions.*;


public class UserInfoModule {


	private static UserInfoModule userInfoModule= new UserInfoModule();
	private static LogModule log= new LogModule("UserInfoModule.txt");
	
	public static UserInfoModel getUserInfo(String username)
	{
		Connection conn=null;
		UserInfoModel ret=null;
		try {
			conn = DatabaseModule.getConnection();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try
		{
			String sqlgetUserInfo="select username,sex,money,question,answer,email from user_info where username = '"+username+"'";
			Statement st= conn.createStatement(); // = conn.prepareCall(sqlLogin);
			
			ResultSet rs = st.executeQuery(sqlgetUserInfo);
			
			if (rs.next())
			{
				ret=new UserInfoModel();
				ret.setUserName(username);
				ret.setSex(rs.getString("sex").charAt(0));
				ret.setMoney(rs.getLong("money"));
				ret.setQuestion(rs.getString("question"));
				ret.setEmail("email");			
			}
			else	//there is no such user!!
			{
				
			}
			

			//debug
			//System.out.println("In UserInfoModule, retval is:\n"+ret.toString());
			log.log(new Date().toLocaleString()+ "\tqueryed user " + ret.getUserName()+" \n" );

			//rs.close();
			//st.close();
			//rs=null;
			st=null;
		}
		catch(SQLException sqle)
		{
			sqle.printStackTrace();
		}

		
		return ret;
	}
/*
	public static void close()
	{
		try {
			rs.close();
			st.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		rs=null;
		st=null;
	}
	*/
	
	public static void main(String[] args) {
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?