annotate tests/SQLcopyinto.java @ 406:bf9f6b6ecf40

Update Copyright year.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Wed, 06 Jan 2021 22:09:32 +0100 (2021-01-06)
parents f523727db392
children 1c8b9aec43a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
251
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
1 /*
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
2 * This Source Code Form is subject to the terms of the Mozilla Public
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
5 *
406
bf9f6b6ecf40 Update Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 391
diff changeset
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
251
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
7 */
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
8
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
9 import java.sql.*;
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
10 import java.io.*;
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
11 import java.util.*;
391
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 358
diff changeset
12 import org.monetdb.mcl.net.MapiSocket;
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 358
diff changeset
13 import org.monetdb.mcl.io.BufferedMCLReader;
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 358
diff changeset
14 import org.monetdb.mcl.io.BufferedMCLWriter;
251
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
15
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
16 /**
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
17 * This program demonstrates how the MonetDB JDBC driver can facilitate
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
18 * in performing COPY INTO ... FROM STDIN sequences.
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
19 * It shows how a data stream via MapiSocket to STDIN can be performed.
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
20 *
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
21 * @author Fabian Groffen, Martin van Dinther
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
22 */
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
23
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
24 public class SQLcopyinto {
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
25 final private static String tablenm = "exampleSQLCopyInto";
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
26
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
27 public static void main(String[] args) throws Exception {
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
28 System.out.println("SQLcopyinto started");
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
29 if (args.length == 0) {
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
30 System.err.println("Error: missing startup argument: the jdbc connection url !");
344
8985d2409c10 Update name of MonetDB JDBC jar file in error msg.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
31 System.err.println("Usage: java -cp monetdb-jdbc-2.29.jre7.jar:. SQLcopyinto \"jdbc:monetdb://localhost:50000/demo?user=monetdb&password=monetdb\"");
251
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
32 System.exit(-1);
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
33 }
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
34 String jdbc_url = args[0];
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
35
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
36 // request a connection to MonetDB server via the driver manager
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
37 Connection conn = DriverManager.getConnection(jdbc_url);
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
38 System.out.println("Connected to MonetDB server");
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
39
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
40 Statement stmt = null;
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
41 ResultSet rs = null;
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
42 try {
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
43 stmt = conn.createStatement();
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
44 stmt.execute("CREATE TABLE IF NOT EXISTS " + tablenm + " (id int, val varchar(24))");
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
45
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
46 fillTableUsingCopyIntoSTDIN(conn);
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
47
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
48 // check content of the table populated via COPY INTO ... FROM STDIN
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
49 System.out.println("Listing uploaded data:");
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
50 rs = stmt.executeQuery("SELECT * FROM " + tablenm);
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
51 if (rs != null) {
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
52 while (rs.next()) {
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
53 System.out.println("Row data: " + rs.getString(1) + ", " + rs.getString(2));
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
54 }
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
55 rs.close();
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
56 rs = null;
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
57 }
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
58
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
59 stmt.execute("DROP TABLE " + tablenm);
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
60
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
61 System.out.println("SQLcopyinto completed");
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
62 } catch (SQLException e) {
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
63 System.err.println("SQLException: " + e.getMessage());
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
64 } catch (Exception e) {
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
65 System.err.println("Exception: " + e.getMessage());
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
66 } finally {
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
67 // free resources
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
68 if (rs != null)
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
69 rs.close();
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
70 if (stmt != null)
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
71 stmt.close();
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
72 // close the JDBC connection to MonetDB server
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
73 if (conn != null)
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
74 conn.close();
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
75 }
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
76 }
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
77
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
78 public static void fillTableUsingCopyIntoSTDIN(Connection mcon) throws Exception {
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
79 System.out.println();
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
80 System.out.println("CopyInto STDIN begin");
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
81
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
82 MapiSocket server = new MapiSocket();
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
83 try {
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
84 server.setLanguage("sql");
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
85
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
86 // extract from MonetConnection object the used connection properties
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
87 String host = mcon.getClientInfo("host");
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
88 int port = Integer.parseInt(mcon.getClientInfo("port"));
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
89 String login = mcon.getClientInfo("user");
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
90 String passw = mcon.getClientInfo("password");
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
91 // System.out.println("host: " + host + " port: " + port + " login: " + login + " passwd: " + passw);
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
92
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
93 System.out.println("Before connecting to MonetDB server via MapiSocket");
257
529b92d09fc6 Resolve compilation warnings when compiled with javac -Xlint
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 251
diff changeset
94 List<String> warning = server.connect(host, port, login, passw);
251
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
95 if (warning != null) {
257
529b92d09fc6 Resolve compilation warnings when compiled with javac -Xlint
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 251
diff changeset
96 for (Iterator<String> it = warning.iterator(); it.hasNext(); ) {
251
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
97 System.out.println("Warning: " + it.next().toString());
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
98 }
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
99 }
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
100 System.out.println("Connected to MonetDB server via MapiSocket");
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
101
391
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 358
diff changeset
102 BufferedMCLReader mclIn = server.getReader();
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 358
diff changeset
103 BufferedMCLWriter mclOut = server.getWriter();
251
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
104
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
105 String error = mclIn.waitForPrompt();
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
106 if (error != null)
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
107 System.err.println("Received start error: " + error);
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
108
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
109 System.out.println("Before sending data to STDIN");
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
110
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
111 // the leading 's' is essential, since it is a protocol marker
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
112 // that should not be omitted, likewise the trailing semicolon
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
113 mclOut.write('s');
358
a06a76170d39 When using \n in SQL strings, the strings need an E prefix.
Sjoerd Mullender <sjoerd@acm.org>
parents: 351
diff changeset
114 mclOut.write("COPY INTO " + tablenm + " FROM STDIN USING DELIMITERS ',',E'\\n';");
251
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
115 mclOut.newLine();
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
116 // now write the row data values as csv data lines to the STDIN stream
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
117 for (int i = 0; i < 40; i++) {
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
118 mclOut.write("" + i + ",val_" + i);
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
119 mclOut.newLine();
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
120 }
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
121 mclOut.writeLine(""); // need this one for synchronisation over flush()
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
122
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
123 error = mclIn.waitForPrompt();
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
124 if (error != null)
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
125 System.err.println("Received error: " + error);
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
126
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
127 mclOut.writeLine(""); // need this one for synchronisation over flush()
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
128
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
129 error = mclIn.waitForPrompt();
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
130 if (error != null)
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
131 System.err.println("Received finish error: " + error);
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
132
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
133 System.out.println("Completed sending data via STDIN");
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
134 } catch (Exception e) {
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
135 System.err.println("Mapi Exception: " + e.getMessage());
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
136 } finally {
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
137 // close connection to MonetDB server
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
138 server.close();
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
139 }
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
140
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
141 System.out.println("CopyInto STDIN end");
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
142 System.out.println();
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
143 }
2b1f650869d6 Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
144 }