public static List<Student> parseExcel(){
//解析excel文件 获取数据
//将每行数据当作一个Student对象放入list集合
List<Student> list = new ArryList<Student>();
return list;
}
public static void updateDataBase(Student stu){
//更新数据库 将Student对象插入数据库
}
public void main(String[] args){
List<Student> list = parseExcel();//读取excel
for(Student stu:list){//遍历集合向数据库插入数据
updateDataBase(stu);
}
}
大致的写了下 具体实现应该没问题吧?
这个你只要配置3个SessionFactory、datasource分别使用3个用户,你可以使用一个jdbcproperties但是里面不要写用户,用户信息在datasource中直接写,然后你需要使用那个用户连接数据库就是用对应的SessionFactory即可!
1读取文本文件,每次读取一行,用BufferedReader
2因为每一行中都是固定的格式,因此解析每一行中的数据。
3将解析的数据保存到数据库。
BufferedReader br = new BufferedReader(new FileReader(new File("aatxt")));
String temp = null;
// 假定这是你写的将数据插入数据库的接口和实现类。
Dao dao = new DaoImpl();
while ((temp = brreadLine()) != null) {
String[] strs = tempsplit("|");
String s1 = strs[0];//如上面的2300
String s2 = strs[1]; // 如上面的62220202222
String s3 = strs[2];//如上面的2000
String s4 = strs[3]; // 如上面的村镇银行3
//还需要写一个方法将数据插入数据库。
daoinsert(s1,s2,s3,s4);
}
brclose();
请自行导入所需要的包,并处理异常。
以上就是关于从excel表格读取数据用Java代码实现批量上传写入数据库全部的内容,包括:从excel表格读取数据用Java代码实现批量上传写入数据库、JAVA的应用数据库,用awt输入信息,如何实现用户可以一次性输入多个信息、Java中怎么实现txt文件批量数据导入到Oracle中,在txt中有一定的格式,解析出来导入到Oracle。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)