public static void main(String[] args) {
Hashtable hs = queryFilterInfo();
Connection conn = null;
ResultSet rs = null;
String sql = null;
//转化Enumeration
Enumeration en = hs.keys();
while(en.hasMoreElements()){
//取得keys值
Object keys = en.nextElement();
//取得数组
String[] info =(String[])hs.get(keys);
sql = "update log_spmo_200704 set province='" + info[0] + "',log_spmo_200704.city='" + info[1] + "' where phone like '"+info[2]+"%'";
}
}
/*-----------------------*/
/*=======================*/
public static Hashtable queryFilterInfo()
{
String filename = "tel_province.txt";
Hashtable ht = new Hashtable();
BufferedReader reader = null;
File logFilef = new File("E:\\工作资料\\work\\tel_province.txt");
try {
reader = new BufferedReader(new FileReader(logFilef));
String line;
while( (line=reader.readLine())!=null )
{
String info[] = line.split(",");
ht.put(info[2],info);
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return ht;
}
Hashtable hs = queryFilterInfo();
Connection conn = null;
ResultSet rs = null;
String sql = null;
//转化Enumeration
Enumeration en = hs.keys();
while(en.hasMoreElements()){
//取得keys值
Object keys = en.nextElement();
//取得数组
String[] info =(String[])hs.get(keys);
sql = "update log_spmo_200704 set province='" + info[0] + "',log_spmo_200704.city='" + info[1] + "' where phone like '"+info[2]+"%'";
}
}
/*-----------------------*/
/*=======================*/
public static Hashtable queryFilterInfo()
{
String filename = "tel_province.txt";
Hashtable ht = new Hashtable();
BufferedReader reader = null;
File logFilef = new File("E:\\工作资料\\work\\tel_province.txt");
try {
reader = new BufferedReader(new FileReader(logFilef));
String line;
while( (line=reader.readLine())!=null )
{
String info[] = line.split(",");
ht.put(info[2],info);
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return ht;
}
本文提供了一个使用Java进行数据库批量更新的示例代码。通过读取文本文件中的数据,将其解析并存储到Hashtable中,然后遍历Hashtable来构建SQL更新语句。此过程展示了如何从文件读取数据、使用Enumeration迭代Hashtable以及构建动态SQL语句。
955

被折叠的 条评论
为什么被折叠?



