Mercurial > hg > monetdb-java
annotate tests/SQLcopyinto.java @ 700:940e266eeccd
Refactor BufferedMCLReader
It used to inherit from BufferedReader but there is no reason for that.
Also, it used to have a method readLine() which
- returned the line read
- stored the linetype
In the new setup we have a method advance() which reads
a line and stores both it and its type.
This makes the code more regular and makes it possible to
peek ahead without consuming.
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Thu, 08 Dec 2022 15:59:17 +0100 (2022-12-08) |
parents | 6aa38e8c0f2d |
children | aeb268156580 |
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 * |
610
6aa38e8c0f2d
Updated Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
479
diff
changeset
|
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2022 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.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
|
11 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
|
12 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
|
13 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
|
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 /** |
2b1f650869d6
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 * 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
|
17 * 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
|
18 * 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
|
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 * @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
|
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 |
2b1f650869d6
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 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
|
24 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
|
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 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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 } |
2b1f650869d6
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 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
|
34 |
2b1f650869d6
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 // 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
|
36 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
|
37 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
|
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 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 |
2b1f650869d6
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 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
|
46 |
2b1f650869d6
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 // 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 } |
2b1f650869d6
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.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
|
55 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
|
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 |
2b1f650869d6
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 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
|
59 |
2b1f650869d6
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 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
|
61 } 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
|
62 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
|
63 } 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
|
64 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
|
65 } 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
|
66 // 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 // 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
|
72 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
|
73 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
|
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 |
2b1f650869d6
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 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
|
78 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
|
79 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
|
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 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
|
82 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
|
83 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
|
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 // 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 // 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
|
91 |
2b1f650869d6
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 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
|
93 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
|
94 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
|
95 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
|
96 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
|
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 } |
2b1f650869d6
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 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
|
100 |
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
|
101 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
|
102 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
|
103 |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 |
2b1f650869d6
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 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
|
109 |
2b1f650869d6
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 // 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
|
111 // 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
|
112 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
|
113 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
|
114 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
|
115 // 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
|
116 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
|
117 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
|
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 } |
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
|
120 |
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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 |
2b1f650869d6
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 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
|
127 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
|
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 { |
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
|
135 // 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
|
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 } |