基础问题 姓名 学号 年龄A 2 20A 2 30A 2 20现在要检查记录的唯一性,有什么好的方法实现。认为1和3是不唯一的。(姓名 学号 年龄 三个一起作为主键)要求要好得方法,不是直接循环去比! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 sql:select 姓名,学号,年龄 from table group by 姓名,学号,年龄 楼上说的是二分法!不是sql,不好意思 我理解错了 需要从什么样的数据结构中 检查?arraylist hashmap 数组 ? 看能不能全部放入一个Set中..... import java.util.*;class t1{ ArrayList arr = new ArrayList(); public t1(){ HashMap temp1 = new HashMap(); temp1.put("name","a"); temp1.put("id","001"); temp1.put("age","12"); HashMap temp2 = new HashMap(); temp2.put("name","b"); temp2.put("id","002"); temp2.put("age","12"); HashMap temp3 = new HashMap(); temp3.put("name","c"); temp3.put("id","003"); temp3.put("age","13"); arr.add(temp1); arr.add(temp2); arr.add(temp3); } public boolean checkValues(HashMap map){ boolean b = false; String name = map.get("name").toString(); String id = map.get("id").toString(); String age = map.get("age").toString(); HashMap temp; String name_temp,id_temp,age_temp; int count = 0; for(int i=0;i<arr.size();i++){ temp = (HashMap)arr.get(i); name_temp = temp.get("name").toString(); id_temp = temp.get("id").toString(); age_temp = temp.get("age").toString(); if(name_temp.equals(name)&&id_temp.equals(id)&&age_temp.equals(age)) count++; } if(count==1)b=true; return b; } public static void main(String args[]){ HashMap map = new HashMap(); map.put("name","c"); map.put("id","003"); map.put("age","13"); boolean b = new t1().checkValues(map); System.out.println (b); }}----------------------------------------------------------------有更好的方法,希望大家写出来! 写一个查询sql好了select count(*) from table1 a,table 2 where a.name=b.name and a.id=b.id and a.age=b.age 如果查出来记录书不为一,那么它肯定是有重复数据了, Connection接口的若干疑问 代码的简化 如何把值放到一行? java 控制热敏打印机打印图像 Hashtable这是什么意思?怎么改? ?关于JDBC连接问题.. 请问怎样将JTable中的输入值更新至TableModel中 ****请问windows的资源管理器中右边的布局是怎么实现的**** 请教关于调用exe文件的问题 急,给多分!!!有关JAVA APPLET安全!!! 这个用hashmap怎么实现?谢谢 少了一个编译命令javac.exe,怎样编译代码了??
arraylist hashmap 数组 ?
import java.util.*;class t1{
ArrayList arr = new ArrayList();
public t1(){
HashMap temp1 = new HashMap();
temp1.put("name","a");
temp1.put("id","001");
temp1.put("age","12");
HashMap temp2 = new HashMap();
temp2.put("name","b");
temp2.put("id","002");
temp2.put("age","12");
HashMap temp3 = new HashMap();
temp3.put("name","c");
temp3.put("id","003");
temp3.put("age","13");
arr.add(temp1);
arr.add(temp2);
arr.add(temp3);
}
public boolean checkValues(HashMap map){
boolean b = false;
String name = map.get("name").toString();
String id = map.get("id").toString();
String age = map.get("age").toString();
HashMap temp;
String name_temp,id_temp,age_temp;
int count = 0;
for(int i=0;i<arr.size();i++){
temp = (HashMap)arr.get(i);
name_temp = temp.get("name").toString();
id_temp = temp.get("id").toString();
age_temp = temp.get("age").toString();
if(name_temp.equals(name)&&id_temp.equals(id)&&age_temp.equals(age))
count++;
}
if(count==1)b=true;
return b;
}
public static void main(String args[]){
HashMap map = new HashMap();
map.put("name","c");
map.put("id","003");
map.put("age","13");
boolean b = new t1().checkValues(map);
System.out.println (b);
}
}
----------------------------------------------------------------有更好的方法,希望大家写出来!
select count(*) from table1 a,table 2 where a.name=b.name and a.id=b.id and a.age=b.age
如果查出来记录书不为一,那么它肯定是有重复数据了,