『壹』 java 从list中取出数据

要看你在 .select(sql, list); //把查出来的数据放到list中了
是怎样保存进去的
一般用 list.get(i);来获得那个保存数据的类
获得具体的数据要list.get(i).getXX(); 在.select(sql, list); 中应该是用setXX()保存进去的

『贰』 怎样用Java获取内存中的数据

方法如下:
首先
创建一个Bean用来存贮要得到的信

public class MonitorInfoBean {
/** 可使用内存. */
private long totalMemory;

/** 剩余内存. */
private long freeMemory;

/** 最大可使用内存. */
private long maxMemory;

/** 操作系统. */
private String osName;

/** 总的物理内存. */
private long totalMemorySize;

/** 剩余的物理内存. */
private long freePhysicalMemorySize;

/** 已使用的物理内存. */
private long usedMemory;

/** 线程总数. */
private int totalThread;

/** cpu使用率. */
private double cpuRatio;

public long getFreeMemory() {
return freeMemory;
}

public void setFreeMemory(long freeMemory) {
this.freeMemory = freeMemory;
}

public long getFreePhysicalMemorySize() {
return freePhysicalMemorySize;
}

public void setFreePhysicalMemorySize(long freePhysicalMemorySize) {
this.freePhysicalMemorySize = freePhysicalMemorySize;
}

public long getMaxMemory() {
return maxMemory;
}

public void setMaxMemory(long maxMemory) {
this.maxMemory = maxMemory;
}

public String getOsName() {
return osName;
}

public void setOsName(String osName) {
this.osName = osName;
}

public long getTotalMemory() {
return totalMemory;
}

public void setTotalMemory(long totalMemory) {
this.totalMemory = totalMemory;
}

public long getTotalMemorySize() {
return totalMemorySize;
}

public void setTotalMemorySize(long totalMemorySize) {
this.totalMemorySize = totalMemorySize;
}

public int getTotalThread() {
return totalThread;
}

public void setTotalThread(int totalThread) {
this.totalThread = totalThread;
}

public long getUsedMemory() {
return usedMemory;
}

public void setUsedMemory(long usedMemory) {
this.usedMemory = usedMemory;
}

public double getCpuRatio() {
return cpuRatio;
}

public void setCpuRatio(double cpuRatio) {
this.cpuRatio = cpuRatio;
}
}

之后,建立bean的接口

public interface IMonitorService {
public MonitorInfoBean getMonitorInfoBean() throws Exception;

}

然后,就是最关键的,得到cpu的利用率,已用内存,可用内存,最大内存等信息。

import java.io.InputStreamReader;
import java.io.LineNumberReader;

import sun.management.ManagementFactory;

import com.sun.management.OperatingSystemMXBean;
import java.io.*;
import java.util.StringTokenizer;

/**

* 获取系统信息的业务逻辑实现类.
* @author GuoHuang
*/
public class MonitorServiceImpl implements IMonitorService {

private static final int CPUTIME = 30;

private static final int PERCENT = 100;

private static final int FAULTLENGTH = 10;

private static final File versionFile = new File("/proc/version");
private static String linuxVersion = null;

/**
* 获得当前的监控对象.
* @return 返回构造好的监控对象
* @throws Exception
* @author GuoHuang
*/
public MonitorInfoBean getMonitorInfoBean() throws Exception {
int kb = 1024;

// 可使用内存
long totalMemory = Runtime.getRuntime().totalMemory() / kb;
// 剩余内存
long freeMemory = Runtime.getRuntime().freeMemory() / kb;
// 最大可使用内存
long maxMemory = Runtime.getRuntime().maxMemory() / kb;

OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory
.getOperatingSystemMXBean();

// 操作系统
String osName = System.getProperty("os.name");
// 总的物理内存
long totalMemorySize = osmxb.getTotalPhysicalMemorySize() / kb;
// 剩余的物理内存
long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize() / kb;
// 已使用的物理内存
long usedMemory = (osmxb.getTotalPhysicalMemorySize() - osmxb
.getFreePhysicalMemorySize())
/ kb;

// 获得线程总数
ThreadGroup parentThread;
for (parentThread = Thread.currentThread().getThreadGroup(); parentThread
.getParent() != null; parentThread = parentThread.getParent())
;
int totalThread = parentThread.activeCount();

double cpuRatio = 0;
if (osName.toLowerCase().startsWith("windows")) {
cpuRatio = this.getCpuRatioForWindows();
}
else {
cpuRatio = this.getCpuRateForLinux();
}

// 构造返回对象
MonitorInfoBean infoBean = new MonitorInfoBean();
infoBean.setFreeMemory(freeMemory);
infoBean.setFreePhysicalMemorySize(freePhysicalMemorySize);
infoBean.setMaxMemory(maxMemory);
infoBean.setOsName(osName);
infoBean.setTotalMemory(totalMemory);
infoBean.setTotalMemorySize(totalMemorySize);
infoBean.setTotalThread(totalThread);
infoBean.setUsedMemory(usedMemory);
infoBean.setCpuRatio(cpuRatio);
return infoBean;
}
private static double getCpuRateForLinux(){
InputStream is = null;
InputStreamReader isr = null;
BufferedReader brStat = null;
StringTokenizer tokenStat = null;
try{
System.out.println("Get usage rate of CUP , linux version: "+linuxVersion);

Process process = Runtime.getRuntime().exec("top -b -n 1");
is = process.getInputStream();
isr = new InputStreamReader(is);
brStat = new BufferedReader(isr);

if(linuxVersion.equals("2.4")){
brStat.readLine();
brStat.readLine();
brStat.readLine();
brStat.readLine();

tokenStat = new StringTokenizer(brStat.readLine());
tokenStat.nextToken();
tokenStat.nextToken();
String user = tokenStat.nextToken();
tokenStat.nextToken();
String system = tokenStat.nextToken();
tokenStat.nextToken();
String nice = tokenStat.nextToken();

System.out.println(user+" , "+system+" , "+nice);

user = user.substring(0,user.indexOf("%"));
system = system.substring(0,system.indexOf("%"));
nice = nice.substring(0,nice.indexOf("%"));

float userUsage = new Float(user).floatValue();
float systemUsage = new Float(system).floatValue();
float niceUsage = new Float(nice).floatValue();

return (userUsage+systemUsage+niceUsage)/100;
}else{
brStat.readLine();
brStat.readLine();

tokenStat = new StringTokenizer(brStat.readLine());
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
String cpuUsage = tokenStat.nextToken();

System.out.println("CPU idle : "+cpuUsage);
Float usage = new Float(cpuUsage.substring(0,cpuUsage.indexOf("%")));

return (1-usage.floatValue()/100);
}

} catch(IOException ioe){
System.out.println(ioe.getMessage());
freeResource(is, isr, brStat);
return 1;
} finally{
freeResource(is, isr, brStat);
}

}

『叁』 在java中如何取出数据库表中某行的数据

limit
限制的是从第几行开始,mysql
默认的有0行

limit
3,1;是从第四行开始,步长为1.希望能帮助你。

『肆』 java 取数据库值

最好的方法就是使用类集list配上范型,例如List<Integer>
list=new
List<Integer>().然后使用for循环讲pk值存入,while(rs.hasnext){list.add(rs.getInt(这里填PK值段的序列))},当然也可以不用范性,但编译有安全警告

『伍』 Java中通过txt文件存储和取出数据

Java中读取txt文件可以使用file类先创建一个对象,然后使用I/O操作,进行读取或者写入操作,示例如下:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class demo2 {
private static String path = "f:/demo1.txt";
private static File file;
static{
file = new File(path);
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}

public static void main(String[] args) throws IOException {
Student stu = new Student(1,"张三",90);
writeDataToFile(file,stu);
readDataFromFile(file);
}

private static void readDataFromFile(File file) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String str = "";
while((str = reader.readLine())!=null){
String[] stuInfo = str.split(",");
System.out.println("学号:"+stuInfo[0]+" 姓名:"+stuInfo[1]+" score:"+stuInfo[2]);
}
}

private static void writeDataToFile(File file,Student stu) throws FileNotFoundException {
PrintWriter out = new PrintWriter(new FileOutputStream(file, true));
out.println(stu.toString());
out.close();
}
}

『陆』 java取数据问题

可以看一下redis,用set数据类型能很好的解决你的问题。

『柒』 java 从字符串提取数据

可以通过java的”substring“方法截取出指定的字符串,前提是知道开始和结束的字符串的值:
String getSignInfo = reqResult.substring(reqResult.indexOf("(") +1, reqResult.indexOf(")"));
解释:上述方法就是截取reqResult字符串的中开始”(“和结束”(“中间部分的内容,”1“就是”(“的长度,之后将获取的结果赋值给”getSignInfo进行输出即可“;
备注:以上方法通用于截取字符串,数字”1“和开始结束字符串根据实际需要修改即可。

『捌』 在java中怎么取出数组中的数据

1.方法:
public final synchronized void setsize(int newsize);
此方法用来定义向量的大小,若向量对象现有成员个数已经超过了newsize的值,则超过部分的多余元素会丢失。
2.程序中定义Enumeration类的一个对象Enumeration是java.util中的一个接口类,
在Enumeration中封装了有关枚举数据集合的方法。
在Enumeration提供了方法hasMoreElement()来判断集合中是否还有其他元素和方法nextElement()来判断集合中是否还有其他元素和方法nextElement()来获取下一个元素。利用这两个方法,可以依次获得集合中的元素。
3.Vector中提供方法:
public final synchronized Enumeration elements();
此方法将向量对象对应到一个枚举类型。java.util包中的其他类中也都有这类方法,以便于用户获取对应的枚举类型。

『玖』 java!怎么取数据啊

List list= //后面是你这个方法的名子
for(int i=0;i<list.size();i++){
String [] array=(String[])list.get(i);
System.out.print(array[0]);
System.out.print(array[0]);
System.out.print(array[0]);
System.out.print(array[0]);
}

『拾』 java中如何从文件中读取数据

分为读字节,读字符两种读法
◎◎◎FileInputStream 字节输入流读文件◎◎◎
public class Maintest {

public static void main(String[] args) throws IOException {

File f=new File("G:\\just for fun\\xiangwei.txt");

FileInputStream fin=new FileInputStream(f);

byte[] bs=new byte[1024];

int count=0;
while((count=fin.read(bs))>0)
{

String str=new String(bs,0,count); //反复定义新变量:每一次都 重新定义新变量,接收新读取的数据

System.out.println(str); //反复输出新变量:每一次都 输出重新定义的新变量
}
fin.close();
}
}

◎◎◎FileReader 字符输入流读文件◎◎◎
public class Maintest {
public static void main(String[] args) throws IOException {

File f=new File("H:\\just for fun\\xiangwei.txt");

FileReader fre=new FileReader(f);

BufferedReader bre=new BufferedReader(fre);

String str="";
while((str=bre.readLine())!=null) //●判断最后一行不存在,为空
{
System.out.println(str);
}
bre.close();
fre.close();

}

}