use of nl.cwi.monetdb.mcl.io.BufferedMCLReader in project pentaho-kettle by pentaho.
the class MonetDBBulkLoader method executeSql.
/*
* executeSQL Uses the MonetDB API to create a new server connection and the associated buffered Reader and Writer to
* execute a single query.
*
* @param Query string
*
* @param Host URI
*
* @param Numerical port
*
* @param Username for establishing the connection
*
* @param Password for establishing the connection
*
* @param database to connect to
*/
protected static void executeSql(String query, String host, int port, String user, String password, String db) throws Exception {
MapiSocket mserver = null;
try {
mserver = getMonetDBConnection(host, port, user, password, db);
BufferedMCLReader in = mserver.getReader();
BufferedMCLWriter out = mserver.getWriter();
String error = in.waitForPrompt();
if (error != null) {
throw new Exception("ERROR waiting for input reader: " + error);
}
// the leading 's' is essential, since it is a protocol
// marker that should not be omitted, likewise the
// trailing semicolon
out.write('s');
System.out.println(query);
out.write(query);
out.write(';');
out.newLine();
out.writeLine("");
String line = null;
while ((line = in.readLine()) != null) {
int type = in.getLineType();
// read till we get back to the prompt
if (type == BufferedMCLReader.PROMPT) {
break;
}
switch(type) {
case BufferedMCLReader.ERROR:
System.err.println(line);
break;
case BufferedMCLReader.RESULT:
System.out.println(line);
break;
default:
// unknown, header, ...
break;
}
}
} finally {
if (mserver != null) {
mserver.close();
}
}
}
Aggregations