
正文
java按照名字查询代码 java按照名字查询代码怎么查
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java按姓名查找如何编写?
我推荐用Access,可以打到jar包中运行,连接还方便。
要么用XML,也可以。
要么将每条信息写成一个类,并且序列化,通过ObjectOutputStream一个个写到文件中,用时再取出来。
相关问答
Q1: 按用户ID查询用户信息的java编程代码 用户id:1003 用户名:sandy 年龄:15 地址:广州 电话:131111111
//jdbc?下面是java通过jdbc从数据库查询表格,返回ResultSet 对象的代码
String sql = "select username,password from account";
String user = request.getParameter("user");
String pass = request.getParameter("password");
int j = 0;
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JDBCTools1.getConnection();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
//ResultSet 对象可以使用rs.getString(序列号从一开始);的方法获得查询结果并显示出来
Q2: 求java中类似学生信息管理系统中按学号,按姓名排序的代码
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Sort {
public static void main(String[] args) {
Student p1 = new Student(1001, "小明", 20);
Student p2 = new Student(1002, "小红", 21);
Student p3 = new Student(1003, "小黑", 19);
ListStudent list = new ArrayListStudent();
list.add(p1);
list.add(p2);
list.add(p3);
Collections.sort(list, new ComparatorStudent() {
/*
* int compare(Student o1, Student o2) 返回一个基本类型的整型, 返回负数表示:o1 小于o2,
* 返回0 表示:o1和o2相等, 返回正数表示:o1大于o2。
*/
public int compare(Student o1, Student o2) {
// 按照学生的学号进行升序排列
if (o1.getId() o2.getId()) {
return 1;
}
if (o1.getId() == o2.getId()) {
return 0;
}
return -1;
}
});
write(list);
System.out.println("---------------------");
Collections.sort(list, new ComparatorStudent() {
/*
* int compare(Student o1, Student o2) 返回一个基本类型的整型, 返回负数表示:o1 小于o2,
* 返回0 表示:o1和o2相等, 返回正数表示:o1大于o2。
*/
public int compare(Student o1, Student o2) {
// 按照学生的年龄进行升序排列
if (o1.getAge() o2.getAge()) {
return 1;
}
if (o1.getAge() == o2.getAge()) {
return 0;
}
return -1;
}
});
write(list);
}
public static void write(ListStudent list) {
for (Student s : list) {
System.out.println(s.getId() + "\t" + s.getName() + "\t"
+ s.getAge());
}
}
}
public class Student {
private int id ;
private String name;
private int age;
//构造方法
public Student(int id,String name,int age){
this.id = id;
this.name = name;
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
Q3: java 根据线程名字查询一个线程,能实现吗?
根据线程名称找到线程,在java中是可以实现的,实现步骤是:
1、首先获取Java VM中当前运行的所有线程
以下代码是用数组返回Java VM中当前运行的所有线程
public static Thread[] findAllThreads()
{
ThreadGroup group = Thread.currentThread().getThreadGroup();
ThreadGroup topGroup = group;
/* 遍历线程组树,获取根线程组 */
while ( group != null )
{
topGroup = group;
group = group.getParent();
}
/* 激活的线程数加倍 */
int estimatedSize = topGroup.activeCount() * 2;
Thread[] slackList = new Thread[estimatedSize];
/* 获取根线程组的所有线程 */
int actualSize = topGroup.enumerate( slackList );
/* copy into a list that is the exact size */
Thread[] list = new Thread[actualSize];
System.arraycopy( slackList, 0, list, 0, actualSize );
return (list);
}
2、遍历线程,比对名称,找到需要寻找的线程
以下代码可得到线程的名称
String name = thread.getName();
关于java按照名字查询代码和java按照名字查询代码怎么查的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。








