Home >Database >navicat >How does navicat process data in batches?

How does navicat process data in batches?

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-08-17 15:31:196637browse

How does navicat process data in batches?

一、使用excel表格

1.打开数据表,按照表的字段在excel中添加数据。注意:表中字段名必须和excel中的名称一致。 

How does navicat process data in batches?

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

How does navicat process data in batches?

How does navicat process data in batches?

相关推荐:《Navicat for mysql使用图文教程

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

How does navicat process data in batches?

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

How does navicat process data in batches?

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

How does navicat process data in batches?

二、使用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 ("+"&#39;"+(i + 1)+"&#39;," +"yystrong"+i+"&#39;,"+"&#39;111&#39;,"
                    +"&#39;"+calcTime("", -(i+1))+"&#39;"+"&#39;0&#39;,"+"&#39;0&#39;,"+"&#39;"+calcTime("", -(i+1))+"&#39;"
                    + "\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打开执行框,复制进去之后选择运行,同样可以导入数据。 

How does navicat process data in batches?

The above is the detailed content of How does navicat process data in batches?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn