usercoinselectbean.java

来自「基于jsp+javaBean的一个很好的网上订购子系统」· Java 代码 · 共 41 行

JAVA
41
字号
package com.buy.bean.coin;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.buy.bean.comm.database.DBConnect;
public class UsercoinSelectBean {
	public String selectUsercoin(String ID,int i){
		String condition;
		if(i==0){
			condition = "select coin from user where id = '"+ID+"'";
		}else if(i==1){
			condition = "select consume from user where id = '"+ID+"'";
		}else if(i==2){
			condition = "select consume + coin from user where id = '"+ID+"'";
		}else if(i==3){
			condition = "select name from user where id = '"+ID+"'";
		}else{
			condition = "select type from user where id = '"+ID+"'";
		}
		ResultSet rs = null;
		Statement sql = null;		
		String str = new String();
		try {
			Connection conn = DBConnect.getConnection();
			sql = conn.createStatement();
			rs = sql.executeQuery(condition);					
			while (rs.next()) {				
				str = rs.getString(1);
			}	
			rs.close();
			sql.close();
			conn.close();
		} catch (SQLException ex) {
			System.out.println("TradeDB SQLException: " + ex.getMessage());
			return new String("can not select");
		}
		return str;
	}
}

⌨️ 快捷键说明

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