- 浏览: 779444 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (258)
- J2SE (18)
- J2EE (33)
- AJAX (4)
- JQuery (1)
- DWR (3)
- Linux/Unix (32)
- PHP (1)
- JSF (8)
- Oracle (34)
- JavaScript (17)
- 批处理 (13)
- ASP (7)
- VBScript (3)
- SqlServer (9)
- Ant (1)
- JDBC (1)
- XML (0)
- MySql (0)
- hibernate (9)
- windows (6)
- .net (0)
- 测试 (2)
- 汇编 (2)
- 网络 (13)
- 其它 (11)
- IDE工具 (6)
- freemarker (4)
- 存储过程 (1)
- 生活 (9)
- python (11)
最新评论
-
d99520y:
hdd unlock我这直接提示can't open driv ...
用PC3000和HDD Unlock解笔记本硬盘密码 -
javaersu:
几个学习Shell的不错网站:shell为您提供了对UNIX系 ...
shell脚本实例 -
zh89233:
一段恶意脚本的分析及思考 -
tiancaicao:
hdd unlock老要联网,一联网就说我这破解不了,让我付费 ...
用PC3000和HDD Unlock解笔记本硬盘密码 -
pythoner126com:
不错,学习了,跟这个作者写的有点像,http://www.yi ...
python对文件进行读写操作
当要用到省市数据的时候,第一反应是这么多,难道要一条一条录入吗?想了想,这也太累了吧,还是写个程序让它自己插入吧,代码如下:
/** * author:qiaolei * 2010-6-25上午09:31:26create */ package com.sucre; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; public class InsertDatas { /** * 批量一次性导入全国省市记录 * @param args */ public static String[][] controlDatas() { String[][] chinaCityStrings = {{"北京市","天津市","河北省","山西省","内蒙古","辽宁省","吉林省","黑龙江省","上海市","江苏省","浙江省","安徽省","福建省","江西省","山东省","河南省","湖北省","湖南省","广东省","广西自治区","海南省","重庆市","四川省"," 贵州省","云南省","西藏自治区","陕西省","甘肃省","青海省","宁夏回族自治区","新疆维吾尔自治区","香港特别行政区","澳门特别行政区","台湾省","其它"},{"北京","东城区","西城区","崇文区","宣武区","朝阳区","丰台区","石景山区"," 海淀区(中关村)","门头沟区","房山区","通州区","顺义区","昌平区","大兴区","怀柔区","平谷区","密云县","延庆县"," 其他"}, {"和平区","河东区","河西区","南开区","红桥区","塘沽区","汉沽区","大港区","西青区","津南区","武清区","蓟县","宁河县","静海县","其他"}, {"石家庄市","张家口市","承德市","秦皇岛市","唐山市","廊坊市","衡水市","沧州市","邢台市","邯郸市","保定市","其他"}, {"太原市","朔州市","大同市","长治市","晋城市","忻州市","晋中市","临汾市","吕梁市","运城市","其他"},{"呼和浩特市","包头市","赤峰市","呼伦贝尔市","鄂尔多斯市","乌兰察布市","巴彦淖尔市","兴安盟","阿拉善盟","锡林郭勒盟","其他"}, {"沈阳市","朝阳市","阜新市","铁岭市","抚顺市","丹东市","本溪市","辽阳市","鞍山市","大连市","营口市","盘锦市","锦州市","葫芦岛市","其他"}, {"长春市","白城市","吉林市","四平市","辽源市","通化市","白山市","延边朝鲜族自治州","其他"}, {"哈尔滨市","七台河市","黑河市","大庆市","齐齐哈尔市","伊春市","佳木斯市","双鸭山市","鸡西市","大兴安岭地区(加格达奇)","牡丹江","鹤岗市","绥化市 ","其他"}, {"黄浦区","卢湾区","徐汇区","长宁区","静安区","普陀区","闸北区","虹口区","杨浦区","闵行区","宝山区","嘉定区","浦东新区","金山区","松江区","青浦区","南汇区","奉贤区","崇明县","其他"}, {"南京市","徐州市","连云港市","宿迁市","淮安市","盐城市","扬州市","泰州市","南通市","镇江市","常州市","无锡市","苏州市","其他"}, {"杭州市","湖州市","嘉兴市","舟山市","宁波市","绍兴市","衢州市","金华市","台州市","温州市","丽水市","其他"}, {"合肥市","宿州市","淮北市","亳州市","阜阳市","蚌埠市","淮南市","滁州市","马鞍山市","芜湖市","铜陵市","安庆市","黄山市","六安市","巢湖市","池州市","宣城市","其他"}, {"福州市","南平市","莆田市","三明市","泉州市","厦门市","漳州市","龙岩市","宁德市","其他"}, {"南昌市","九江市","景德镇市","鹰潭市","新余市","萍乡市","赣州市","上饶市","抚州市","宜春市","吉安市","其他"}, {"济南市","聊城市","德州市","东营市","淄博市","潍坊市","烟台市","威海市","青岛市","日照市","临沂市","枣庄市","济宁市","泰安市","莱芜市","滨州市","菏泽市","其他"}, {"郑州市","三门峡市","洛阳市","焦作市","新乡市","鹤壁市","安阳市","濮阳市","开封市","商丘市","许昌市","漯河市","平顶山市","南阳市","信阳市","周口市","驻马店市","其他"}, {"武汉市","十堰市","襄樊市","荆门市","孝感市","黄冈市","鄂州市","黄石市","咸宁市","荆州市","宜昌市","随州市","恩施土家族苗族自治州","仙桃市","天门市","潜江市","神农架林区","其他"}, {"长沙市","张家界市","常德市","益阳市","岳阳市","株洲市","湘潭市","衡阳市","郴州市","永州市","邵阳市","怀化市","娄底市","湘西土家族苗族自治州","其他"}, {"广州市","清远市市","韶关市","河源市","梅州市","潮州市","汕头市","揭阳市","汕尾市"," 惠州市","东莞市","深圳市","珠海市","中山市","江门市","佛山市","肇庆市","云浮市","阳江市","茂名市","湛江市"," 其他"}, {"南宁市","桂林市","柳州市","梧州市","贵港市","玉林市","钦州市","北海市","防城港市","崇左市","百色市","河池市","来宾市","贺州市","其他"}, {"海口市","三亚市","其他"}, {"渝中区","大渡口区","江北区","沙坪坝区","九龙坡区","南岸区","北碚区","万盛区","双桥区","渝北区","巴南区","万州区","涪陵区","黔江区","长寿区","合川市","永川市","江津市","南川市","綦江县","潼南县","铜梁县","大足县","璧山县","垫江县","武隆县","丰都县","城口县","开县","巫溪县","巫山县","奉节县","云阳县","忠县","石柱土家族自治县","彭水苗族土家族自治县","酉阳土家族苗族自治县","秀山土家族苗族自治县","其他"}, {"成都市","广元市","绵阳市","德阳市","南充市","广安市","遂宁市","内江市","乐山市","自贡市","泸州市","宜宾市","攀枝花市","巴中市","资阳市","眉山市","雅安","阿坝藏族羌族自治州","甘孜藏族自治州","凉山彝族自治州县","其他"}, {"贵阳市","六盘水市","遵义市","安顺市","毕节地区","铜仁地区","黔东南苗族侗族自治州","黔南布依族苗族自治州","黔西南布依族苗族自治州","其他"}, {"昆明市","曲靖市","玉溪市","保山市","昭通市","丽江市","普洱市","临沧市","宁德市","德宏傣族景颇族自治州","怒江傈僳族自治州","楚雄彝族自治州","红河哈尼族彝族自治州","文山壮族苗族自治州","大理白族自治州","迪庆藏族自治州","西双版纳傣族自治州","其他"}, {"拉萨市","那曲地区","昌都地区","林芝地区","山南地区","日喀则地区","阿里地区","其他"}, {"西安市","延安市","铜川市","渭南市","咸阳市","宝鸡市","汉中市","安康市","商洛市","其他"}, {"兰州市 ","嘉峪关市","金昌市","白银市","天水市","武威市","酒泉市","张掖市","庆阳市","平凉市","定西市","陇南市","临夏回族自治州","甘南藏族自治州","其他"}, {"西宁市","海东地区","海北藏族自治州","黄南藏族自治州","玉树藏族自治州","海南藏族自治州","果洛藏族自治州","海西蒙古族藏族自治州","其他"}, {"银川市","石嘴山市","吴忠市","固原市","中卫市","其他"}, {"乌鲁木齐市","克拉玛依市","喀什地区","阿克苏地区","和田地区","吐鲁番地区","哈密地区","塔城地区","阿勒泰地区","克孜勒苏柯尔克孜自治州","博尔塔拉蒙古自治州","昌吉回族自治州伊犁哈萨克自治州","巴音郭楞蒙古自治州","河子市","阿拉尔市","五家渠市","图木舒克市","其他"}, {"香港","其他"}, {"澳门","其他"}, {"台湾","其他"}}; return chinaCityStrings; } public static void main(String[] args) { String[][] citys = controlDatas(); Session session = HibernateSessionFactory.getSession(); Transaction tx = session.beginTransaction(); int fid = 0; int dictIdI =110; String state = "1"; for (int i = 0; i < citys.length; i++) { for (int j = 0; j < citys[i].length; j++) { tx.begin(); TDictItem dictItem = new TDictItem(); dictItem.setDictitemName(citys[i][j].trim()); dictItem.setDictitemAbbr(ChineseToEnglish.getPYString(citys[i][j].trim())); dictItem.setDictitemSeq(j + 1); dictItem.setDictitemValue(String.valueOf(j + 1)); dictItem.setDictitemDictid(dictIdI); dictItem.setDictitemFid(fid); dictItem.setDictitemState(state); session.save(dictItem); tx.commit(); } if(i == 0){//第一次循环插入的是全国的省,这个时候fid应该为0,从第二次循环开始就插入是全国的市了,所以要取省的id fid = 1366; } fid+=1; } session.close(); } }
不管你有多少,全部正确插入,呵呵,省下来的时间可以去做别的事了。
- DatasHandle.rar (373.9 KB)
- 下载次数: 23
发表评论
-
java多线程编程
2010-07-05 11:04 11731、 认识Thread和Runnable J ... -
将汉语转换成拼音(全拼和缩写)
2010-06-29 14:00 1915程序里面用到了开源的包,可以将汉语转成全拼或者缩写,代码如下: ... -
java正则表达式
2010-06-29 13:52 1657一、开篇说说 ^ 和 $ 想必很多人都对正则表达式都头 ... -
java删除文件
2010-05-27 13:37 0/** * * * 2007- ... -
出现Bad version number in .class file这个问题时,要注意三个方面
2010-03-24 14:07 1179java.lang.UnsupportedClassVersi ... -
Java经典算法
2010-03-17 14:29 2661/** *插入排序(WHILE ... -
MyEclipse7.5注册机源码
2010-01-27 16:37 1634MyEclipse7.5注册机源码大家可以通过运行的方法得到自 ... -
测试服务器响应时间
2010-01-14 11:15 4930所谓的响应时间,就是从客户端开始发出请求到服务器最后返回请求时 ... -
能用map的时候尽量不用List
2009-12-17 11:05 1256今天在做项目的时候,用到了map,以前很少用的,一直在用Lis ... -
关于数组和List之间相互转换的方法
2009-10-10 09:58 11291.List转换成为数组(这里的List是实体是ArrayLi ... -
过滤代码中的html标签
2009-09-07 14:20 875public String html2Text(String ... -
java中空串""与null的区别
2009-06-26 13:16 1353问题:很容易对java中的""(空 ... -
在DispatchAction中使用中文按钮
2009-05-10 11:31 1238有两个方面要注意: 一、在资源文件里要有key value的 ... -
关于中文乱码问题的一些解决方案和经验
2009-03-15 12:51 12051.字节和unicode java内核是unicode的 ... -
在JAVA中日期和字符串之间的相互转换
2009-02-21 09:07 1734在JAVA中日期和字符串之间是可以相互转换的,主要用到了Sim ... -
用JAVA程序调用DOS命令
2009-02-20 21:36 1710网上的代码是有问题,我做了一些修改,具体详细代码如下: pac ... -
equals 和 == 的区别
2008-12-31 12:28 1293equals 方法(是String类从它的超类Object中 ... -
输出某种编码的字符串
2008-10-15 09:22 1398Public String translate (String ...
相关推荐
这是一篇将最新的省市区json数据通过java读取之后,遍历然后存储到数据库中的资源,json数据和数据库sql都包含在内,.java文件中是通过url访问的,controller可能需要稍微改一下,不想搞得话就直接运行sql文件吧!
省市县数据库通常包含中国行政区域的数据,如省份、城市、区县等,这些数据在不同的应用中被广泛使用。Access是一种轻量级的关系型数据库管理系统,适用于小型数据存储和管理,而Oracle则是一款功能强大的企业级...
SQL导入脚本通常是为了简化将CSV数据批量导入数据库的过程,通过执行预先编写好的SQL命令,可以快速有效地将数据载入到表中。 “脚本”一词可能指的是一个或多个脚本文件,这些文件包含了将CSV数据导入MySQL数据库...
这篇教程“C#数据库教程6-ADO.NET用户数据导入数据库的几种类型”将详细介绍如何利用C#和ADO.NET框架处理不同类型的用户数据导入到SQL Server数据库的过程。以下是对这些知识点的详细讲解: 一、文本数据导入数据库...
### SQL Server 批量导入省市县街道四级...通过上述方法,我们可以有效地将大量的省市县街道四级数据批量导入到SQL Server数据库中。合理的设计和高效的导入策略不仅可以提高工作效率,还能保证数据的准确性和一致性。
6. **数据导入**:一旦表结构建立完毕,我们可以使用INSERT INTO语句或者BULK INSERT命令来批量导入数据。如果数据量大,考虑使用ETL工具(如SSIS)或者Power Query进行高效导入。 7. **验证数据**:导入完成后,...
对于大规模数据的导入,可以编写脚本批量处理,提高效率。此外,还可以利用数据库管理系统提供的API或ORM(对象关系映射)框架,如Python的SQLAlchemy,简化操作。 总之,这个任务涉及到了数据库设计的基本概念,...
在本例中,"省市数据表.sql"文件很可能包含了多个这样的CREATE TABLE语句,用于定义省和市的数据结构。 表结构通常包括字段(Field)和字段类型(Data Type)。对于省市数据库,可能有以下字段: 1. `id`:作为主键...
- **数据导入导出**:SQL Server的BCP(Bulk Copy Program)工具或SSIS(SQL Server Integration Services)可用于批量导入省市数据,提高数据迁移效率。 - **权限管理**:通过角色和用户权限设置,控制对省市数据...
2. 数据导入:如何使用SQL语句批量导入数据到MySQL数据库中。 3. 地理编码:理解行政编码的作用和使用方式,以及其在数据处理中的重要性。 4. 地理位置信息:如何处理和存储经纬度信息,以及在GIS应用中的使用。 5. ...
在IT行业中,数据库管理和数据操作是至关重要的环节...这种做法在数据迁移、初始化系统或者批量导入数据时非常有用。然而,实际应用中还需要考虑数据的校验、错误处理以及性能优化等问题,确保整个流程的稳定性和效率。
2. **插入数据(INSERT INTO)**:将全国省市区的数据逐条或批量插入到对应的表中。 3. **索引(INDEX)**:为提高查询效率,可能会为频繁使用的字段创建索引。 4. **数据更新(UPDATE)**:如果数据有变动,可以...
这可能涉及到批量导入新的或更新的行政区域数据,或者通过触发器和定时任务自动同步外部数据源。 6. **安全性与权限**:在MySQL中,设置用户权限和访问控制至关重要,以确保数据的安全性。根据应用需求,可以为不同...
4. **MYSQL导入脚本**:db.txt很可能是MySQL的导入脚本,用于将这些文本数据批量导入到MySQL数据库中。脚本可能包含了创建表格、设置字段类型和导入数据的SQL语句,便于将文本数据转化为结构化的数据库格式。 5. **...
在这个项目中,由于可能涉及大量的省市数据,推荐使用SAX或StAX解析器。这里以SAX为例,我们需要创建一个`DefaultHandler`子类,重写其中的`startElement()`、`endElement()`和`characters()`方法来处理解析过程中的...
导入过程通常涉及到创建表结构、设置字段类型,然后使用`LOAD DATA INFILE`语句将文本数据批量导入。 接着,提及的MS-SQL Server是微软开发的企业级数据库管理系统,与MySQL类似,它也支持SQL标准,并且在大型企业...
4. **数据导入与管理**:使用SQL脚本`ms_citycode.sql`,用户可以将数据导入到本地或远程的MySQL服务器上,创建所需的数据库表并填充数据。这通常涉及使用`CREATE TABLE`语句创建表结构,然后用`INSERT INTO`语句...
在提供的insert语句中,通常会包含批量插入或单条插入,确保数据一次性准确无误地导入数据库。为了优化数据库性能,可以使用事务处理,确保数据的原子性,即一组操作要么全部成功,要么全部失败。同时,合理使用索引...
导入SQL数据到数据库时,首先要创建相应的表结构,然后使用`LOAD DATA INFILE`或`INSERT INTO`语句将数据批量导入。在处理大数据量时,可以采用分区表、索引优化等技术提高查询性能。同时,为了保护数据,还需要设定...