package highgo.OtherTest;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
public class ChongfuTest {
public static void main(String[] args) {
// String a = "王海霞";
// String b = "杨硕";
// String c = "张呈娟";
// String d = "李翔艳";
String d = "吕安琪";
// String e = "吕安琪";
String a = "王";
String b = "杨";
String c = "张";
String d = "李";
String e = "吕";
ArrayList<String> arr = new ArrayList<String>();
arr.add(a);
arr.add(b);
arr.add(c);
arr.add(d);
arr.add(e);
// System.out.println(get(arr,arr));
boolean isRepeat = arr.size() != new HashSet<String>(arr).size();
System.out.println(isRepeat);
// ArrayList<String> arraylist = new ArrayList<String>();
Connection conncolumns = null;
Statement stmtcolumns = null;
conncolumns = getConnection("jdbc:sqlserver://192.168.70.66:1433;DatabaseName=ecology", "sa", "Admin2019");
String sqlcolumns = "select u8bxrxm from ecology.dbo.uf_cwzzdz ";
try {
stmtcolumns = conncolumns.createStatement();
ResultSet rscolumns = stmtcolumns.executeQuery(sqlcolumns);
while (rscolumns.next()) {
// Retrieve by column name
String id = rscolumns.getString("u8bxrxm");
// Display values
// arraylist.add(id);
arr.add(id);
}
conncolumns.close();
stmtcolumns.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// System.out.println(get(arr,arraylist));
boolean isRepeat2 = arr.size() != new HashSet<String>(arr).size();
System.out.println(isRepeat2);
}
public static String get(ArrayList<String> arr,ArrayList<String> arr2) {
int length = arr.size();
int length2 = arr2.size();
String result = null;
for(int i = 0; i < length; i++) {
for(int j = 0; j < length2;j++) {
if(i!=j) {
if(arr.get(i).equals(arr2.get(j))) {
return "ERROR";
} else {
result = "SUCCESS";
}
}
}
}
return result;
}
//连接数据库
public static Connection getConnection(String ip, String name, String password) {
Connection con = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(ip, name, password);
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
public static void getRepeateNum( int[] num) {
int NumChange;
System.out.println("重复数字是:");
for(int index = 0; index < num.length; index++) {
while(num[index] != index) {
if(num[index] == num[num[index]]) {
System.out.print(num[index]+" ");
break;
} else {
NumChange = num[num[index]];
num[num[index]] = num[index];
num[index] = NumChange;
}
}
}
}
}