annotate tests/SQLcopyinto.java @ 358:a06a76170d39

When using \n in SQL strings, the strings need an E prefix.
author Sjoerd Mullender <sjoerd@acm.org>
date Thu, 09 Apr 2020 13:47:46 +0200 (2020-04-09)
parents 77b1b7e8a4b1
children f523727db392
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 *
350
54137aeb1f92 Update Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 344
diff changeset
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2020 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.*;
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
12 import nl.cwi.monetdb.mcl.net.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
13
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
14 /**
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 * 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
16 * 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
17 * 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
18 *
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 * @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
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
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 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
23 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
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
25 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
26 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
27 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
28 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
29 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
30 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
31 }
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 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
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 // 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
35 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
36 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
37
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 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
39 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
40 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
41 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
42 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
43
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 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
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 // 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
47 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
48 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
49 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
50 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
51 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
52 }
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 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
54 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
55 }
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
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 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
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 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
60 } 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
61 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
62 } 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
63 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
64 } 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
65 // 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
66 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
67 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
68 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
69 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
70 // 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
71 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
72 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
73 }
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 }
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 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
77 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
78 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
79
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 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
81 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
82 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
83
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 // 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
85 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
86 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
87 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
88 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
89 // 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
90
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("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
92 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
93 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
94 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
95 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
96 }
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 }
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 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
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 nl.cwi.monetdb.mcl.io.BufferedMCLReader mclIn = server.getReader();
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 nl.cwi.monetdb.mcl.io.BufferedMCLWriter mclOut = server.getWriter();
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
102
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
103 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
104 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
105 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
106
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.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
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 // 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
110 // 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
111 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
112 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
113 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
114 // 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
115 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
116 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
117 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
118 }
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.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
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 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
122 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
123 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
124
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 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
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 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
128 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
129 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
130
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.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
132 } 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
133 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
134 } 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
135 // 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
136 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
137 }
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
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 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
140 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
141 }
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 }