List of usage examples for java.sql SQLException printStackTrace
public void printStackTrace()
From source file:dbutils.ExampleJDBC.java
/** * BeanListHandler ResultSet??ListList/*from w w w . ja v a 2 s .com*/ */ public static void getBeanListData() { Connection conn = getConnection(); QueryRunner qr = new QueryRunner(); try { ResultSetHandler<Student> rsh = new BeanHandler(Student.class); Student usr = qr.query(conn, "SELECT id, name, gender, age, team_id as teamId FROM test_student WHERE id=1", rsh); System.out.println(StringUtils.center("findById", 50, '*')); System.out.println("id=" + usr.getId() + " name=" + usr.getName() + " gender=" + usr.getGender()); List<Student> results = (List<Student>) qr.query(conn, "SELECT id, name, gender, age, team_id as teamId FROM test_student LIMIT 10", new BeanListHandler(Student.class)); System.out.println(StringUtils.center("findAll", 50, '*')); for (Student result : results) { System.out.println( "id=" + result.getId() + " name=" + result.getName() + " gender=" + result.getGender()); } } catch (SQLException e) { e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } }
From source file:de.dakror.virtualhub.server.DBManager.java
public static Tags tags(File f, String catalog, Tags t) { try {/* w ww . j av a2 s . c o m*/ if (t == null) { ResultSet rs = connection.createStatement().executeQuery("SELECT TAGS FROM TAGS WHERE PATH = \"" + f.getPath().replace("\\", "/") + "\" AND CATALOG = \"" + catalog + "\""); if (!rs.next()) return new Tags(); return new Tags(rs.getString(1).split(", ")); } else { if (t.getTags().length == 0) connection.createStatement().executeUpdate("DELETE FROM TAGS WHERE PATH = \"" + f.getPath().replace("\\", "/") + "\" AND CATALOG = \"" + catalog + "\""); else connection.createStatement() .executeUpdate("INSERT OR REPLACE INTO TAGS VALUES(\"" + f.getPath().replace("\\", "/") + "\", \"" + catalog + "\", \"" + t.serialize() + "\")"); } } catch (SQLException e1) { e1.printStackTrace(); } return null; }
From source file:de.dakror.virtualhub.server.DBManager.java
public static Eticet eticet(File f, String catalog, Eticet e) { try {/*from w w w. j a v a2 s.c o m*/ if (e == Eticet.NULL) { ResultSet rs = connection.createStatement() .executeQuery("SELECT ETICET FROM ETICETS WHERE PATH = \"" + f.getPath().replace("\\", "/") + "\" AND CATALOG = \"" + catalog + "\""); if (!rs.next()) return Eticet.NONE; return Eticet.values()[rs.getInt(1)]; } else { if (e == Eticet.NONE) connection.createStatement().executeUpdate("DELETE FROM ETICETS WHERE PATH = \"" + f.getPath().replace("\\", "/") + "\" AND CATALOG = \"" + catalog + "\""); else connection.createStatement().executeUpdate( "INSERT OR REPLACE INTO ETICETS VALUES(\"" + f.getPath().replace("\\", "/") + "\"," + e.ordinal() + ") AND CATALOG = \"" + catalog + "\""); } } catch (SQLException e1) { e1.printStackTrace(); } return null; }
From source file:com.dangdang.ddframe.rdb.common.sql.base.AbstractSQLTest.java
private static void createSchema(final DatabaseType dbType) { try {//from ww w .j ava 2 s . co m Connection conn; for (int i = 0; i < 10; i++) { for (String database : Arrays.asList("db", "dbtbl", "nullable", "master", "slave")) { conn = initialConnection(database + "_" + i, dbType); RunScript.execute(conn, new InputStreamReader(AbstractDBUnitTest.class.getClassLoader() .getResourceAsStream("integrate/schema/table/" + database + ".sql"))); conn.close(); } } String database = "tbl"; conn = initialConnection(database, dbType); RunScript.execute(conn, new InputStreamReader(AbstractDBUnitTest.class.getClassLoader() .getResourceAsStream("integrate/schema/table/tbl.sql"))); conn.close(); } catch (final SQLException ex) { ex.printStackTrace(); } }
From source file:info.extensiblecatalog.OAIToolkit.db.DButil.java
public static DatabaseMetaData getMetadata() { try {//from w ww . ja va 2 s . c om return getConnection().getMetaData(); } catch (SQLException e) { e.printStackTrace(); prglog.error("[PRG] " + e); return null; } catch (Exception e) { e.printStackTrace(); prglog.error("[PRG] " + e); return null; } }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.db.DeviceTargetResolverTest.java
@AfterClass public static void teardown() { try {/*from w ww .j a va2s. c o m*/ //delete stuff from tag so that other test that recreate device data don't run into issues DBTestUtil.cleanTables(new String[] { "mmxTag" }, new BasicDataSourceConnectionProvider(ds)); ds.close(); } catch (SQLException e) { e.printStackTrace(); } }
From source file:com.data2semantics.yasgui.server.db.ConnectionFactory.java
/** * Get database connection// w ww . j ava2s . com * * @param configDir * @return * @throws JSONException * @throws ClassNotFoundException * @throws SQLException * @throws FileNotFoundException * @throws IOException * @throws ParseException */ public static Connection getConnection(File configDir) throws JSONException, ClassNotFoundException, SQLException, FileNotFoundException, IOException, ParseException { JSONObject config = ConfigFetcher.getJsonObjectFromPath(configDir); Connection connect = null; try { connect = connect( config.getString(SettingKeys.MYSQL_HOST) + "/" + config.getString(SettingKeys.MYSQL_DB), config.getString(SettingKeys.MYSQL_USERNAME), config.getString(SettingKeys.MYSQL_PASSWORD)); applyDeltas(connect, configDir); } catch (SQLException e) { e.printStackTrace(); System.out.println("either db doesnt exist, or there is an error in our deltas"); //connect without db selector, create db, and create new connector connect = connect(config.getString(SettingKeys.MYSQL_HOST), config.getString(SettingKeys.MYSQL_USERNAME), config.getString(SettingKeys.MYSQL_PASSWORD)); connect = updateDatabase(connect, config, configDir); } return connect; }
From source file:info.extensiblecatalog.OAIToolkit.db.DButil.java
public static String showInfo() { StringBuffer sb = new StringBuffer(); DatabaseMetaData meta = getMetadata(); Connection conn = null;//from w w w .j a v a 2 s . c o m try { conn = getConnection(); } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } sb.append("Connection: "); if (null == conn) { sb.append(" (is null)"); } else { sb.append(" (is ok)"); } if (null == meta) { sb.append(", [unknown server]"); } else { try { sb.append(", server: " + meta.getDatabaseProductName() + " " + meta.getDatabaseProductVersion()); } catch (SQLException e) { e.printStackTrace(); prglog.error("[PRG] " + e); } } sb.append(", user: '" + user + "'"); sb.append(", password: '" + password + "'"); sb.append(", database: '" + database + "'"); return sb.toString(); }
From source file:com.sun.portal.os.portlets.PortletChartUtilities.java
private static JFreeChart createChart(ResourceRequest request) { JFreeChart chart = null;//from w w w . ja v a 2 s.c o m try { PortletPreferences prefs = request.getPreferences(); if (prefs == null) throw new NoPreferredDbSetException("Preferences not passed in from portlet"); String type = prefs.getValue(Constants.PREF_CHART_TYPE, PIE_CHART); debugMessage("Chart type :" + type); if (type.equals(PIE_CHART)) { String sql = prefs.getValue(Constants.PREF_PIE_CHART_SQL, DEFAULT_PIE_CHART_SQL); PieDataset data = (PieDataset) generatePieDataSet(getDatabaseConnection(request), sql); chart = ChartFactory.createPieChart("Pie Chart", data, true, true, false); } else if (type.equals(BAR_CHART)) { String sql = prefs.getValue(Constants.PREF_BAR_CHART_SQL, DEFAULT_BAR_CHART_SQL); JDBCCategoryDataset data = (JDBCCategoryDataset) generateBarChartDataSet( getDatabaseConnection(request), sql); chart = ChartFactory.createBarChart3D("Bar Chart", "Category", "Value", data, PlotOrientation.VERTICAL, true, true, false); } else if (type.equals(TIME_CHART)) { String sql = prefs.getValue(Constants.PREF_TIME_SERIES_SQL, DEFAULT_TIME_SERIES_SQL); JDBCXYDataset data = (JDBCXYDataset) generateXYDataSet(getDatabaseConnection(request), sql); chart = ChartFactory.createTimeSeriesChart("Time Series Chart", "Date", "Rate", data, true, true, false); } } catch (NoPreferredDbSetException npdbs) { npdbs.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return chart; }
From source file:com.srotya.tau.ui.Utils.java
public static void createDatabase(String dbConnectionString, String dbName, String user, String pass, String driver) throws Exception { Connection conn = null;/*from w w w . jav a2 s . co m*/ Statement stmt = null; try { // STEP 2: Register JDBC driver Class.forName(driver); // STEP 3: Open a connection System.out.println("Connecting to database..."); conn = DriverManager.getConnection(dbConnectionString, user, pass); // STEP 4: Execute a query System.out.println("Creating database..."); stmt = conn.createStatement(); String sql = "CREATE DATABASE IF NOT EXISTS " + dbName; stmt.executeUpdate(sql); System.out.println("Database created successfully..."); } finally { // finally block used to close resources try { if (stmt != null) stmt.close(); } catch (SQLException se2) { } // nothing we can do try { if (conn != null) conn.close(); } catch (SQLException se) { se.printStackTrace(); } // end finally try } // end try }