package com.buy.bean.coin;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import com.buy.bean.comm.database.DBConnect;
public class UsercoinSelectBean {
//查询用户信息的方法
public String selectUsercoin(String ID, int i) {
//声明查询语句的字符串类型变量
String condition = null;
if(i == 0) {
//如果参数i为0表示查询用户电子货币余额
condition = "select coin from user where id = " + ID;
} else if(i == 1) {
//如果参数i为1表示查询用户已花费的电子货币
condition = "select consume from user where id = " + ID;
} else if(i == 2) {
//如果参数i为2表示查询用户累计的电子货币
condition = "select coin + consume from user where id = " + ID;
} else if(i == 3) {
//如果参数i为3表示查询用户的姓名
condition = "select name from user where id = " + ID;
} else if(i == 4) {
//如果参数i为4表示查询用户的类型
condition = "select type from user where id = " + ID;
}
ResultSet rs = null;
Statement sql = null;
String str = new String();
try {
int coin;
//获得数据库连接
Connection conn = DBConnect.getConnection();
//建立Statement
sql = conn.createStatement();
//执行数据库查询
rs = sql.executeQuery(condition);
//取结果集记录中的第一个字符
while(rs.next()) {
str = rs.getString(1);
}
//将取得的字符串转化成整型
coin = Integer.parseInt(str);
//关闭结果集
rs.close();
//关闭Statement
sql.close();
//关闭连接
conn.close();
} catch (Exception e) {
//如果查询错误
return new String("can not select");
}
//返回结果
return str;
}
}
用resultSet.getString( )方法
name和type都是varchar类型的 前面几个整型都能打印出来
varchar类型的打印不出来
查询语句正常 放入数据库里能检索到
求教什么问题。