从数据从另一个数据库导入的下拉菜单中将数据插入数据库

时间:2019-01-02 21:23:52

标签: php mysql forms

我创建了一个下拉菜单,从中可以从数据库中输入选项,但是,我希望将所选的选项输入到另一个数据库中。

2018;11;Oldenburg;total_sales;monthly;145840.00

有人可以给我建议怎么做吗?记录已提交,但这是下拉列表的最后一行,而不是他选择的那一行。

1 个答案:

答案 0 :(得分:1)

您从哪里获取将来自帖子的选择值。

您可能希望将其添加到已编写的sql查询上方。

import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
import org.apache.commons.compress.utils.IOUtils;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;

[..]

private static final int MAX_CHUNK_SIZE = 16000000;

public void compressTarGzChunks(String inputDirPath, String outputDirPath) throws Exception {
    PipedInputStream in = new PipedInputStream();
    final PipedOutputStream out = new PipedOutputStream(in);
    new Thread(() -> {
        try {
            int chunkIndex = 0;
            int n = 0;
            byte[] buffer = new byte[8192];
            do {
                String chunkFileName = String.format("archive-part%d.tar.gz", chunkIndex);
                try (OutputStream fOut = Files.newOutputStream(Paths.get(outputDirPath, chunkFileName));
                     BufferedOutputStream bOut = new BufferedOutputStream(fOut);
                     GzipCompressorOutputStream gzOut = new GzipCompressorOutputStream(bOut)) {

                    int currentChunkSize = 0;
                    if (chunkIndex > 0) {
                        gzOut.write(buffer, 0, n);
                        currentChunkSize += n;
                    }
                    while ((n = in.read(buffer)) != -1 && currentChunkSize + n < MAX_CHUNK_SIZE) {
                        gzOut.write(buffer, 0, n);
                        currentChunkSize += n;
                    }
                    chunkIndex++;
                }
            } while (n != -1);
            in.close();
        } catch (IOException e) {
            // logging and exception handling should go here
        }
    }).start();

    try (TarArchiveOutputStream tOut = new TarArchiveOutputStream(out)) {
        compressTar(tOut, inputDirPath, "");
    }
}

private static void compressTar(TarArchiveOutputStream tOut, String path, String base)
        throws IOException {
    File file = new File(path);
    String entryName = base + file.getName();
    TarArchiveEntry tarEntry = new TarArchiveEntry(file, entryName);
    tarEntry.setSize(file.length());
    tOut.putArchiveEntry(tarEntry);

    if (file.isFile()) {
        try (FileInputStream in = new FileInputStream(file)) {
            IOUtils.copy(in, tOut);
            tOut.closeArchiveEntry();
        }
    } else {
        tOut.closeArchiveEntry();
        File[] children = file.listFiles();
        if (children != null) {
            for (File child : children) {
                compressTar(tOut, child.getAbsolutePath(), entryName + "/");
            }
        }
    }
}

我也看不到

这样的选择定义
public void concatTarGzChunks(List<InputStream> sortedTarGzChunks, String outputFile) throws IOException {
    try {
        try (FileOutputStream fos = new FileOutputStream(outputFile)) {
            for (InputStream in : sortedTarGzChunks) {
                int len;
                byte[] buf = new byte[1024 * 1024];
                while ((len = in.read(buf)) != -1) {
                    fos.write(buf, 0, len);
                }
            }
        }
    } finally {
        sortedTarGzChunks.forEach(is -> {
            try {
                is.close();
            } catch (IOException e) {
                // logging and exception handling should go here
            }
        });
    }
}

在打印选项之前和while循环之外。