List of usage examples for java.sql SQLException printStackTrace
public void printStackTrace()
From source file:de.tudarmstadt.ukp.csniper.resbuild.EvaluationItemFixer2.java
public static void main(String[] args) { connect(HOST, DATABASE, USER, PASSWORD); Map<Integer, String> items = new HashMap<Integer, String>(); Map<Integer, String> failed = new HashMap<Integer, String>(); // fetch coveredTexts of dubious items and clean it PreparedStatement select = null; PreparedStatement update = null; try {/*from ww w .j a va 2 s. c om*/ StringBuilder selectQuery = new StringBuilder(); selectQuery.append("SELECT * FROM cachedparse WHERE pennTree = 'ERROR' OR pennTree = ''"); select = connection.prepareStatement(selectQuery.toString()); log.info("Running query [" + selectQuery.toString() + "]."); ResultSet rs = select.executeQuery(); // CSVWriter writer; String text; JCas jcas = JCasFactory.createJCas(); String updateQuery = "UPDATE CachedParse SET pennTree = ? WHERE collectionId = ? AND documentId = ? AND beginOffset = ? AND endOffset = ?"; update = connection.prepareStatement(updateQuery); // File base = new File(""); AnalysisEngine sentences = createEngine(DummySentenceSplitter.class); AnalysisEngine tokenizer = createEngine(StanfordSegmenter.class, StanfordSegmenter.PARAM_CREATE_SENTENCES, false, StanfordSegmenter.PARAM_CREATE_TOKENS, true); AnalysisEngine parser = createEngine(StanfordParser.class, StanfordParser.PARAM_WRITE_CONSTITUENT, true, // StanfordParser.PARAM_CREATE_DEPENDENCY_TAGS, true, StanfordParser.PARAM_WRITE_PENN_TREE, true, StanfordParser.PARAM_LANGUAGE, "en", StanfordParser.PARAM_VARIANT, "factored"); while (rs.next()) { String collectionId = rs.getString("collectionId"); String documentId = rs.getString("documentId"); int beginOffset = rs.getInt("beginOffset"); int endOffset = rs.getInt("endOffset"); text = retrieveCoveredText(collectionId, documentId, beginOffset, endOffset); jcas.setDocumentText(text); jcas.setDocumentLanguage("en"); sentences.process(jcas); tokenizer.process(jcas); parser.process(jcas); // writer = new CSVWriter(new FileWriter(new File(base, documentId + ".csv")); System.out.println("Updating " + text); for (PennTree p : JCasUtil.select(jcas, PennTree.class)) { String tree = StringUtils.normalizeSpace(p.getPennTree()); update.setString(1, tree); update.setString(2, collectionId); update.setString(3, documentId); update.setInt(4, beginOffset); update.setInt(5, endOffset); update.executeUpdate(); System.out.println("with tree " + tree); break; } jcas.reset(); } } catch (SQLException e) { log.error("Exception while selecting: " + e.getMessage()); } catch (UIMAException e) { e.printStackTrace(); } finally { closeQuietly(select); closeQuietly(update); } // write logs // BufferedWriter bwf = null; // BufferedWriter bws = null; // try { // bwf = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File( // LOG_FAILED)), "UTF-8")); // for (Entry<Integer, String> e : failed.entrySet()) { // bwf.write(e.getKey() + " - " + e.getValue() + "\n"); // } // // bws = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File( // LOG_SUCCESSFUL)), "UTF-8")); // for (Entry<Integer, String> e : items.entrySet()) { // bws.write(e.getKey() + " - " + e.getValue() + "\n"); // } // } // catch (IOException e) { // log.error("Got an IOException while writing the log files."); // } // finally { // IOUtils.closeQuietly(bwf); // IOUtils.closeQuietly(bws); // } log.info("Texts for [" + items.size() + "] items need to be cleaned up."); // update the dubious items with the cleaned coveredText // PreparedStatement update = null; // try { // String updateQuery = "UPDATE EvaluationItem SET coveredText = ? WHERE id = ?"; // // update = connection.prepareStatement(updateQuery); // int i = 0; // for (Entry<Integer, String> e : items.entrySet()) { // int id = e.getKey(); // String coveredText = e.getValue(); // // // update item in database // update.setString(1, coveredText); // update.setInt(2, id); // update.executeUpdate(); // log.debug("Updating " + id + " with [" + coveredText + "]"); // // // show percentage of updated items // i++; // int part = (int) Math.ceil((double) items.size() / 100); // if (i % part == 0) { // log.info(i / part + "% finished (" + i + "/" + items.size() + ")."); // } // } // } // catch (SQLException e) { // log.error("Exception while updating: " + e.getMessage()); // } // finally { // closeQuietly(update); // } closeQuietly(connection); }
From source file:TerminalMonitor.java
static public void main(String args[]) { DriverPropertyInfo[] required; StringBuffer buffer = new StringBuffer(); Properties props = new Properties(); boolean connected = false; Driver driver;//from w w w.j a va 2s . co m String url; int line = 1; // Mark current input line if (args.length < 1) { System.out.println("Syntax: <java -Djdbc.drivers=DRIVER_NAME " + "TerminalMonitor JDBC_URL>"); return; } url = args[0]; // We have to get a reference to the driver so we can // find out what values to prompt the user for in order // to make a connection. try { driver = DriverManager.getDriver(url); } catch (SQLException e) { e.printStackTrace(); System.err.println("Unable to find a driver for the specified " + "URL."); System.err.println("Make sure you passed the jdbc.drivers " + "property on the command line to specify " + "the driver to be used."); return; } try { required = driver.getPropertyInfo(url, props); } catch (SQLException e) { e.printStackTrace(); System.err.println("Unable to get driver property information."); return; } input = new BufferedReader(new InputStreamReader(System.in)); // some drivers do not implement this properly // if that is the case, prompt for user name and password try { if (required.length < 1) { props.put("user", prompt("user: ")); props.put("password", prompt("password: ")); } else { // for each required attribute in the driver property info // prompt the user for the value for (int i = 0; i < required.length; i++) { if (!required[i].required) { continue; } props.put(required[i].name, prompt(required[i].name + ": ")); } } } catch (IOException e) { e.printStackTrace(); System.err.println("Unable to read property info."); return; } // Make the connection. try { connection = DriverManager.getConnection(url, props); } catch (SQLException e) { e.printStackTrace(); System.err.println("Unable to connect to the database."); } connected = true; System.out.println("Connected to " + url); // Enter into a user input loop while (connected) { String tmp, cmd; // Print a prompt if (line == 1) { System.out.print("TM > "); } else { System.out.print(line + " -> "); } System.out.flush(); // Get the next line of input try { tmp = input.readLine(); } catch (java.io.IOException e) { e.printStackTrace(); return; } // Get rid of extra space in the command cmd = tmp.trim(); // The user wants to commit pending transactions if (cmd.equals("commit")) { try { connection.commit(); System.out.println("Commit successful."); } catch (SQLException e) { System.out.println("Error in commit: " + e.getMessage()); } buffer = new StringBuffer(); line = 1; } // The user wants to execute the current buffer else if (cmd.equals("go")) { if (!buffer.equals("")) { try { executeStatement(buffer); } catch (SQLException e) { System.out.println(e.getMessage()); } } buffer = new StringBuffer(); line = 1; continue; } // The user wants to quit else if (cmd.equals("quit")) { connected = false; continue; } // The user wants to clear the current buffer else if (cmd.equals("reset")) { buffer = new StringBuffer(); line = 1; continue; } // The user wants to abort a pending transaction else if (cmd.equals("rollback")) { try { connection.rollback(); System.out.println("Rollback successful."); } catch (SQLException e) { System.out.println("An error occurred during rollback: " + e.getMessage()); } buffer = new StringBuffer(); line = 1; } // The user wants version info else if (cmd.startsWith("show")) { DatabaseMetaData meta; try { meta = connection.getMetaData(); cmd = cmd.substring(5, cmd.length()).trim(); if (cmd.equals("version")) { showVersion(meta); } else { System.out.println("show version"); // Bad arg } } catch (SQLException e) { System.out.println("Failed to load meta data: " + e.getMessage()); } buffer = new StringBuffer(); line = 1; } // The input that is not a keyword should appended be to the buffer else { buffer.append(" " + tmp); line++; continue; } } try { connection.close(); } catch (SQLException e) { System.out.println("Error closing connection: " + e.getMessage()); } System.out.println("Connection closed."); }
From source file:edu.lternet.pasta.token.TokenManager.java
/** * @param args//from ww w. j av a 2 s.co m */ public static void main(String[] args) { ConfigurationListener.configure(); String token = "sz46tDcFxqLby2TtlBARREdqGFSSRFbjSHPvMw0hgXLsG2uGlDW" + "rOzjf/zM7Yd7g4n8pK5qKzohvP9UdYqf/xyx/RBAUU1QYwmUXTA" + "5NnUZ5qHjYCtx3Y+DgwyNsQPoz6dQqR92BWWsWb39BilwfaRoyg" + "8vRbmJ3CFRslvB5WfUqEI2OIhD2h3VyYXq8V7f8X4IZDSHWMWNX" + "YMuxC3eQ+A=="; String uid = "ucarroll"; TokenManager tokenManager = new TokenManager(); try { tokenManager.setToken(uid, token); } catch (SQLException e) { logger.error(e); e.printStackTrace(); } catch (ClassNotFoundException e) { logger.error(e); e.printStackTrace(); } try { System.out.println(tokenManager.getToken(uid)); } catch (SQLException e) { logger.error(e); e.printStackTrace(); } catch (ClassNotFoundException e) { logger.error(e); e.printStackTrace(); } }
From source file:edu.ku.brc.specify.toycode.mexconabio.CopyPlantsFromGBIF.java
public static void main(String[] args) { CopyPlantsFromGBIF app = new CopyPlantsFromGBIF(); try {//from w ww . j av a 2 s. c o m app.connectToSrc("localhost", "3306", "gbif", "root", "root"); app.connectToDst("localhost", "3306", "plants", "root", "root"); app.connectToCOLTaxa("localhost", "3306", "col_taxa", "root", "root"); app.processNullKingdom(); //app.processNonNullNonPlantKingdom(); app.cleanup(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:edu.ku.brc.specify.toycode.RegAdder.java
/** * @param args// www .ja v a 2s. c om */ public static void main(String[] args) { String dbName = "stats"; String itUsername = "root"; String itPassword = "root"; DBConnection colDBConn = null; Connection connection = null; try { DatabaseDriverInfo driverInfo = DatabaseDriverInfo.getDriver("MySQL"); String connStr = driverInfo.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open, "localhost", dbName, itUsername, itPassword, driverInfo.getName()); System.err.println(connStr); colDBConn = DBConnection.createInstance(driverInfo.getDriverClassName(), driverInfo.getDialectClassName(), dbName, connStr, itUsername, itPassword); connection = colDBConn.createConnection(); BasicSQLUtils.setDBConnection(connection); RegAdder ra = new RegAdder(connection); boolean doReg = false; if (doReg) { ra.process("/Users/rods/reg.dat", "register", true); } else { ra.process("/Users/rods/track.dat", "track", true); } } catch (Exception ex) { ex.printStackTrace(); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:ProxyAuthTest.java
public static void main(String[] args) throws Exception { if (args.length < 4) { System.out.println("Usage ProxyAuthTest <host> <port> <server_principal> <proxy_user> [testTab]"); System.exit(1);// w w w . j a v a 2s .c o m } File currentResultFile = null; String[] beeLineArgs = {}; Class.forName(driverName); String host = args[0]; String port = args[1]; String serverPrincipal = args[2]; String proxyUser = args[3]; String url = null; if (args.length > 4) { tabName = args[4]; } generateData(); generateSQL(null); try { /* * Connect via kerberos and get delegation token */ url = "jdbc:hive2://" + host + ":" + port + "/default;principal=" + serverPrincipal; con = DriverManager.getConnection(url); System.out.println("Connected successfully to " + url); // get delegation token for the given proxy user String token = ((HiveConnection) con).getDelegationToken(proxyUser, serverPrincipal); if ("true".equals(System.getProperty("proxyAuth.debug", "false"))) { System.out.println("Got token: " + token); } con.close(); // so that beeline won't kill the JVM System.setProperty(BEELINE_EXIT, "true"); // connect using principal via Beeline with inputStream url = "jdbc:hive2://" + host + ":" + port + "/default;principal=" + serverPrincipal; currentResultFile = generateSQL(null); beeLineArgs = new String[] { "-u", url, "-n", "foo", "-p", "bar" }; System.out.println("Connection with kerberos, user/password via args, using input rediction"); BeeLine.mainWithInputRedirection(beeLineArgs, inpStream); compareResults(currentResultFile); // connect using principal via Beeline with inputStream url = "jdbc:hive2://" + host + ":" + port + "/default;principal=" + serverPrincipal; currentResultFile = generateSQL(null); beeLineArgs = new String[] { "-u", url, "-n", "foo", "-p", "bar", "-f", scriptFileName }; System.out.println("Connection with kerberos, user/password via args, using input script"); BeeLine.main(beeLineArgs); compareResults(currentResultFile); // connect using principal via Beeline with inputStream url = "jdbc:hive2://" + host + ":" + port + "/default;principal=" + serverPrincipal; currentResultFile = generateSQL(url + " foo bar "); beeLineArgs = new String[] { "-u", url, "-f", scriptFileName }; System.out.println("Connection with kerberos, user/password via connect, using input script"); BeeLine.main(beeLineArgs); compareResults(currentResultFile); // connect using principal via Beeline with inputStream url = "jdbc:hive2://" + host + ":" + port + "/default;principal=" + serverPrincipal; currentResultFile = generateSQL(url + " foo bar "); beeLineArgs = new String[] { "-u", url, "-f", scriptFileName }; System.out.println("Connection with kerberos, user/password via connect, using input redirect"); BeeLine.mainWithInputRedirection(beeLineArgs, inpStream); compareResults(currentResultFile); /* * Connect using the delegation token passed via configuration object */ System.out.println("Store token into ugi and try"); storeTokenInJobConf(token); url = "jdbc:hive2://" + host + ":" + port + "/default;auth=delegationToken"; con = DriverManager.getConnection(url); System.out.println("Connecting to " + url); runTest(); con.close(); // connect using token via Beeline with inputStream url = "jdbc:hive2://" + host + ":" + port + "/default"; currentResultFile = generateSQL(null); beeLineArgs = new String[] { "-u", url, "-n", "foo", "-p", "bar", "-a", "delegationToken" }; System.out.println("Connection with token, user/password via args, using input redirection"); BeeLine.mainWithInputRedirection(beeLineArgs, inpStream); compareResults(currentResultFile); // connect using token via Beeline using script url = "jdbc:hive2://" + host + ":" + port + "/default"; currentResultFile = generateSQL(null); beeLineArgs = new String[] { "-u", url, "-n", "foo", "-p", "bar", "-a", "delegationToken", "-f", scriptFileName }; System.out.println("Connection with token, user/password via args, using input script"); BeeLine.main(beeLineArgs); compareResults(currentResultFile); // connect using token via Beeline using script url = "jdbc:hive2://" + host + ":" + port + "/default"; currentResultFile = generateSQL(url + " foo bar "); beeLineArgs = new String[] { "-a", "delegationToken", "-f", scriptFileName }; System.out.println("Connection with token, user/password via connect, using input script"); BeeLine.main(beeLineArgs); compareResults(currentResultFile); // connect using token via Beeline using script url = "jdbc:hive2://" + host + ":" + port + "/default"; currentResultFile = generateSQL(url + " foo bar "); System.out.println("Connection with token, user/password via connect, using input script"); beeLineArgs = new String[] { "-f", scriptFileName, "-a", "delegationToken" }; BeeLine.main(beeLineArgs); compareResults(currentResultFile); /* * Connect via kerberos with trusted proxy user */ url = "jdbc:hive2://" + host + ":" + port + "/default;principal=" + serverPrincipal + ";hive.server2.proxy.user=" + proxyUser; con = DriverManager.getConnection(url); System.out.println("Connected successfully to " + url); runTest(); ((HiveConnection) con).cancelDelegationToken(token); con.close(); } catch (SQLException e) { System.out.println("*** SQLException: " + e.getMessage() + " : " + e.getSQLState()); e.printStackTrace(); } /* verify the connection fails after canceling the token */ try { url = "jdbc:hive2://" + host + ":" + port + "/default;auth=delegationToken"; con = DriverManager.getConnection(url); throw new Exception("connection should have failed after token cancelation"); } catch (SQLException e) { // Expected to fail due to canceled token } }
From source file:edu.ku.brc.specify.toycode.mexconabio.BuildTags.java
public static void main(String[] args) { try {/*from www. j av a 2 s .com*/ BuildTags awg = new BuildTags(); awg.setUp(); awg.createDBConnection("localhost", "3306", BuildTags.databaseName, "root", "root"); awg.createSrcDBConnection("localhost", "3306", "tags", "root", "root"); awg.process(); awg.cleanup(); } catch (SQLException ex) { ex.printStackTrace(); } }
From source file:edu.ku.brc.specify.dbsupport.SpecifyDeleteHelper.java
/** * @param args/*from w w w .j av a 2 s .c o m*/ */ public static void main(String[] args) { DBTableIdMgr.getInstance().getByShortClassName(CollectingEvent.class.getSimpleName()); // Preload SpecifyDeleteHelper sdh = new SpecifyDeleteHelper(); try { // if (sdh.isRecordShared(CollectingEvent.class, 1016)) // { // System.out.println("CollectingEvent 1016 is shared"); // } else // { // System.out.println("CollectingEvent 1016 is NOT shared"); // } // if (sdh.isRecordShared(Locality.class, 132)) // { // System.out.println("Locality 132 is shared"); // } else // { // System.out.println("Locality 132 is NOT shared"); // } if (sdh.isRecordShared(Geography.class, 54907)) { System.out.println("Geography 54907 is shared"); } else { System.out.println("Geography 54907 is NOT shared"); } } catch (SQLException e) { e.printStackTrace(); } }
From source file:edu.ku.brc.specify.conversion.SpecifyDBConverter.java
/** * @param args/*w w w .j a va 2s .c o m*/ * @throws Exception */ public static void main(String args[]) throws Exception { /*try { List<String> list = FileUtils.readLines(new File("/Users/rods/drop.sql")); Vector<String> list2 = new Vector<String>(); for (String line : list) { list2.add(line+";"); } FileUtils.writeLines(new File("/Users/rods/drop2.sql"), list2); return; } catch (Exception ex) { ex.printStackTrace(); }*/ // Set App Name, MUST be done very first thing! UIRegistry.setAppName("Specify"); //$NON-NLS-1$ log.debug("********* Current [" + (new File(".").getAbsolutePath()) + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ UIRegistry.setEmbeddedDBPath(UIRegistry.getDefaultEmbeddedDBPath()); // on the local machine AppBase.processArgs(args); final SpecifyDBConverter converter = new SpecifyDBConverter(); Logger logger = LogManager.getLogger("edu.ku.brc"); if (logger != null) { logger.setLevel(Level.ALL); System.out.println("Setting " + logger.getName() + " to " + logger.getLevel()); } logger = LogManager.getLogger(edu.ku.brc.dbsupport.HibernateUtil.class); if (logger != null) { logger.setLevel(Level.INFO); System.out.println("Setting " + logger.getName() + " to " + logger.getLevel()); } // Create Specify Application SwingUtilities.invokeLater(new Runnable() { public void run() { try { if (!System.getProperty("os.name").equals("Mac OS X")) { UIManager.setLookAndFeel(new Plastic3DLookAndFeel()); PlasticLookAndFeel.setPlasticTheme(new DesertBlue()); } } catch (Exception e) { log.error("Can't change L&F: ", e); } Pair<String, String> namePair = null; try { if (converter.selectedDBsToConvert(false)) { namePair = converter.chooseTable("Select a DB to Convert", "Specify 5 Databases", true); } } catch (SQLException ex) { ex.printStackTrace(); JOptionPane.showConfirmDialog(null, "The Converter was unable to login.", "Error", JOptionPane.CLOSED_OPTION); } if (namePair != null) { frame = new ProgressFrame("Converting"); converter.processDB(); } else { JOptionPane.showConfirmDialog(null, "The Converter was unable to login.", "Error", JOptionPane.CLOSED_OPTION); System.exit(0); } } }); }
From source file:Main.java
public static void close() { try {//from w ww . jav a2 s .com con.close(); } catch (SQLException e) { e.printStackTrace(); } }