Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of batch data processing in navicat

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Xiaobian to share with you navicat batch processing data method, I hope you read this article after the harvest, let us discuss it together!

I. Use of Excel Forms

1. Open the data table and add data to excel according to the fields of the table. Note: field names in the table must be consistent with the names in excel.

2.打开navicat,在表结构处右键选择"导入向导",选择excel文件,找到excel文件所在的位置。注意:一个excel表格里可以有多个sheet,所以如果全选中的话,可以一次性分别导入多个数据表,但是一定要保证字段名不要错,否则导入的时候会显示错误。

3.选择下一步,到设置附加选项时,"栏位名称"是excel中字段的那一行,"第一个数据行"是数据开始的那一行。

4.下一步,选择"开始",执行之后,选择"关闭"。

5.在数据表中刷新,发现数据就都导进来了。

二、使用insert语句(FileWriter批量写入)

定义一个写语句到文件的方法,在for循环里面定义自己需要的格式。在这里笔者想让时间变化,于是写了一个让时间减一的方法,其实在这张表里时间无所谓,但是在文章开头笔者有提到,当需要添加一年的数据时,或者某一段时间的每一天都要添加时,就有必要定义这个方法了。

import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.sql.Date;import java.text.SimpleDateFormat;import java.util.Calendar;public class UserTest { public static void main(String[] args) { try { writeToFile(); //readFromFile(); } catch (IOException e) { e.printStackTrace(); } } /** * DOC 往文件里写入数据. * * @throws IOException */ private static void writeToFile() throws IOException { String writerContent = "";// 要写入的文本 File file = new File("F:\\user.txt");// 要写入的文本文件 if (!file.exists()) {// 如果文件不存在,则创建该文件 file.createNewFile(); } FileWriter writer = new FileWriter(file);// 获取该文件的输出流 for (int i = 0 ;i < 10; i ++ ) { writerContent = "insert into `user` VALUES ("+"'"+(i + 1)+"'," +"yystrong"+i+"',"+"'111'," +"'"+calcTime("", -(i+1))+"'"+"'0',"+"'0',"+"'"+calcTime("", -(i+1))+"'" + "\r\n"; writer.write(writerContent);// 写内容 } writer.flush();// 清空缓冲区,立即将输出流里的内容写到文件里 writer.close();// 关闭输出流,施放资源 } /** * * @param type 往前计算的类型(week、month、year,""表示day * @param count 往前计算的数量 * @return */ private static String calcTime(String type ,int count){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar calendar = Calendar.getInstance(); if (type .equals("week")) { //周 calendar.add(Calendar.WEEK_OF_YEAR, count); }else if (type .equals("month")) { //月 calendar.add(Calendar.MONTH, count); }else if (type .equals("year")) { //12个月 calendar.add(Calendar.MONTH, count); }else { //日 calendar.add(Calendar.DATE, count); } java.util.Date date = calendar.getTime(); return sdf.format(date); }}

执行之后,在f盘的根目录下就会创建一个user.txt的文件夹,里面有insert语句,然后在navicat里面选择ctrl+q打开执行框,复制进去之后选择运行,同样可以导入数据。

看完了这篇文章,相信你对navicat批量处理数据的方法有了一定的了解,想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report