Mercurial > hg > monetdb-java
annotate tests/SQLcopyinto.java @ 970:f90d811e97eb default tip
Adjust getTableTypes() test for new table type: LOCAL TEMPORARY VIEW, added in 11.53.4 (Mar2025-SP1)
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 03 Apr 2025 15:01:33 +0200 (3 days ago) |
parents | d416e9b6b3d0 |
children |
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 /* |
833
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
2 * SPDX-License-Identifier: MPL-2.0 |
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
3 * |
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
|
4 * 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
|
5 * 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
|
6 * 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
|
7 * |
937
d416e9b6b3d0
Update Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
917
diff
changeset
|
8 * Copyright 2024, 2025 MonetDB Foundation; |
833
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
9 * Copyright August 2008 - 2023 MonetDB B.V.; |
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
10 * Copyright 1997 - July 2008 CWI. |
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
|
11 */ |
2b1f650869d6
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 |
2b1f650869d6
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 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
|
14 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
|
15 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
|
16 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
|
17 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
|
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 /** |
2b1f650869d6
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 * 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
|
21 * 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
|
22 * 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
|
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 * @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
|
25 */ |
2b1f650869d6
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 |
917
c2164decf7f1
Add final to classes
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
833
diff
changeset
|
27 public final class SQLcopyinto { |
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
|
28 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
|
29 |
2b1f650869d6
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 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
|
31 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
|
32 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
|
33 System.err.println("Error: missing startup argument: the jdbc connection url !"); |
479
1c8b9aec43a6
Update usage text to the latest monetdb-jdbc-3.0.jre8.jar
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
34 System.err.println("Usage: java -cp monetdb-jdbc-3.0.jre8.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
|
35 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
|
36 } |
2b1f650869d6
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 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
|
38 |
2b1f650869d6
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 // 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
|
40 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
|
41 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
|
42 |
2b1f650869d6
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 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 |
2b1f650869d6
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 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
|
50 |
2b1f650869d6
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 // 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
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 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
|
59 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
|
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 |
2b1f650869d6
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 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
|
63 |
2b1f650869d6
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 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
|
65 } 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
|
66 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
|
67 } 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
|
68 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
|
69 } 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
|
70 // 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 // 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
|
76 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
|
77 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
|
78 } |
2b1f650869d6
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 |
2b1f650869d6
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 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
|
82 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
|
83 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
|
84 |
2b1f650869d6
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 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
|
86 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
|
87 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
|
88 |
2b1f650869d6
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 // 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 // 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
|
95 |
2b1f650869d6
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 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 } |
2b1f650869d6
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 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
|
104 |
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
|
105 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
|
106 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
|
107 |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
108 String error = mclIn.discardRemainder(); |
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
|
109 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
|
110 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
|
111 |
2b1f650869d6
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 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
|
113 |
2b1f650869d6
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 // 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
|
115 // 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
|
116 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
|
117 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
|
118 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
|
119 // 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
|
120 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
|
121 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
|
122 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
|
123 } |
479
1c8b9aec43a6
Update usage text to the latest monetdb-jdbc-3.0.jre8.jar
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
124 |
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
|
125 mclOut.writeLine(""); // need this one for synchronisation over flush() |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
126 error = mclIn.discardRemainder(); |
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
|
127 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
|
128 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
|
129 |
2b1f650869d6
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 mclOut.writeLine(""); // need this one for synchronisation over flush() |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
131 error = mclIn.discardRemainder(); |
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
|
132 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
|
133 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
|
134 |
2b1f650869d6
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.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
|
136 } 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
|
137 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
|
138 } finally { |
479
1c8b9aec43a6
Update usage text to the latest monetdb-jdbc-3.0.jre8.jar
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
139 // close MapiSocket connection to MonetDB server |
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
|
140 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
|
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 |
2b1f650869d6
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 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
|
144 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
|
145 } |
2b1f650869d6
Improved example program SQLcopyinto,java and added to tests directory for automatic testing
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
146 } |