List of usage examples for java.sql SQLException getCause
public synchronized Throwable getCause()
From source file:org.snaker.engine.access.jdbc.BeanPropertyHandler.java
/** * ?beanclass??/*from w w w . j a v a 2 s . c o m*/ * @param mappedClass */ protected void initialize(Class<T> mappedClass) { this.mappedClass = mappedClass; this.mappedFields = new HashMap<String, PropertyDescriptor>(); PropertyDescriptor[] pds = null; try { /** * bean?? */ pds = propertyDescriptors(mappedClass); } catch (SQLException e) { throw new SnakerException(e.getMessage(), e.getCause()); } for (PropertyDescriptor pd : pds) { if (pd.getWriteMethod() != null) { this.mappedFields.put(pd.getName().toLowerCase(), pd); String underscoredName = underscoreName(pd.getName()); if (!pd.getName().toLowerCase().equals(underscoredName)) { this.mappedFields.put(underscoredName, pd); } } } }
From source file:eu.udig.catalog.teradata.TeradataDatabaseConnectionRunnable.java
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try {//from ww w . j av a 2s.com Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put(DBTYPE.key, (Serializable) new TeradataDialect().dbType); params.put(HOST.key, host); params.put(PORT.key, port); params.put(USER.key, username); params.put(PASSWD.key, password); params.put(DATABASE.key, "dbc"); BasicDataSource source = TeradataServiceExtension.getFactory().createDataSource(params); Connection connection = source.getConnection(); try { Statement statement = connection.createStatement(); if (statement.execute("SELECT F_TABLE_SCHEMA FROM SYSSPATIAL.GEOMETRY_COLUMNS")) { ResultSet resultSet = statement.getResultSet(); while (resultSet.next()) { databaseNames.add(resultSet.getString(1).trim()); } } statement.close(); } finally { if (connection != null) { connection.close(); } if (source != null) { source.close(); } } } catch (SQLException e) { checkSqlException(e); } catch (Exception e) { if (e.getCause() instanceof SQLException) { checkSqlException((SQLException) e.getCause()); } else { Activator.log("Error connecting to datasource", e); result = "Unrecognized connection failure. Check parameters and database."; } } ran = true; }
From source file:net.refractions.udig.catalog.internal.postgis.ui.PostgisDatabaseConnectionRunnable.java
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try {/*from w w w . j av a 2 s .c o m*/ Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put(DBTYPE.key, (Serializable) new PostgisServiceDialect().dbType); params.put(HOST.key, host); params.put(PORT.key, port); params.put(USER.key, username); params.put(PASSWD.key, password); params.put(DATABASE.key, "template1"); BasicDataSource source = PostgisServiceExtension2.getFactory().createDataSource(params); Connection connection = source.getConnection(); try { Statement statement = connection.createStatement(); if (statement.execute("SELECT datname FROM pg_database")) { ResultSet resultSet = statement.getResultSet(); while (resultSet.next()) { databaseNames.add(resultSet.getString("datname")); } } statement.close(); } finally { if (connection != null) { connection.close(); } if (source != null) { source.close(); } } } catch (SQLException e) { checkSqlException(e); } catch (IOException e) { if (e.getCause() instanceof SQLException) { checkSqlException((SQLException) e.getCause()); } else { PostgisPlugin.log("Error connecting to datasource", e); result = "Unrecognized connection failure. Check parameters and database."; } } ran = true; }
From source file:fuel.gui.stats.StationStatsPanel.java
private void refreshGraphs() { graphContainer.removeAll();//from www . j a v a 2 s . co m DefaultPieDataset usageDataset = new DefaultPieDataset(); try { for (Station station : database.getStations()) { ResultSet thisStation = database .Query("SELECT SUM(liter) FROM fuelrecords WHERE stationId = " + station.getId(), true); thisStation.next(); usageDataset.setValue(station.toString(), thisStation.getInt("1")); } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause()); } JFreeChart usagePieChart = ChartFactory.createPieChart3D("", usageDataset, true, true, false); PiePlot3D plot3 = (PiePlot3D) usagePieChart.getPlot(); plot3.setForegroundAlpha(0.6f); //plot3.setCircular(true); JPanel usagePieChartPanel = new ChartPanel(usagePieChart); usagePieChartPanel.setBorder( BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Tankstation verhouding"))); usagePieChartPanel.setPreferredSize(new java.awt.Dimension(320, 240)); DefaultPieDataset fuelDataset = new DefaultPieDataset(); try { ResultSet numberResults = database.Query("SELECT DISTINCT typeOfGas FROM fuelrecords", true); while (numberResults.next()) { ResultSet thisStation = database.Query("SELECT SUM(liter) FROM fuelrecords WHERE typeOfGas = '" + numberResults.getString("typeOfGas") + "'", true); thisStation.next(); fuelDataset.setValue(numberResults.getString("typeOfGas"), thisStation.getInt("1")); } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause()); } JFreeChart fuelPieChart = ChartFactory.createPieChart3D("", fuelDataset, true, true, false); PiePlot3D plot2 = (PiePlot3D) fuelPieChart.getPlot(); plot2.setForegroundAlpha(0.6f); //plot3.setCircular(true); JPanel fuelPieChartPanel = new ChartPanel(fuelPieChart); fuelPieChartPanel.setBorder( BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Brandstof verhouding"))); fuelPieChartPanel.setPreferredSize(new java.awt.Dimension(320, 240)); DefaultCategoryDataset barDataset = new DefaultCategoryDataset(); try { ResultSet motorThing = database.Query("SELECT cost/liter,date FROM fuelrecords ORDER BY date ASC", true); while (motorThing.next()) { barDataset.addValue(motorThing.getDouble("1"), motorThing.getString("date"), "Prijs per liter"); } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause()); } JFreeChart barChart = ChartFactory.createBarChart3D("", // chart title "", // domain axis label "Aantal", // range axis label barDataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips? false // URLs? ); CategoryPlot plot = barChart.getCategoryPlot(); BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer(); renderer.setDrawBarOutline(false); ChartPanel barChartPanel = new ChartPanel(barChart); barChartPanel.getChartRenderingInfo().setEntityCollection(null); barChartPanel.setBorder(BorderFactory.createTitledBorder("Prijs per liter")); barChartPanel.setPreferredSize(new java.awt.Dimension(320, 240)); JPanel piePanel = new JPanel(new GridLayout(0, 2)); piePanel.add(usagePieChartPanel); piePanel.add(fuelPieChartPanel); graphContainer.add(piePanel); graphContainer.add(barChartPanel); revalidate(); repaint(); }
From source file:com.taobao.datax.plugins.reader.sqlserverreader.SqlServerReader.java
@Override public List<PluginParam> split(PluginParam param) { List<PluginParam> params; if (StringUtils.isBlank(this.sql)) { logger.info("No user-defined sql found, begin to construct sql-statement ."); params = new SqlServerSplitter(param).split(); } else {/*from ww w . j a v a2s . c o m*/ logger.info(String.format("User-defined sql [%s] found", sql)); params = super.split(param); } String singleSql = params.get(0).getValue(ParamKey.sql); try { this.connect(); param.setMyMetaData(DBUtils.genMetaData(this.connection, singleSql)); } catch (SQLException e) { logger.error(ExceptionTracker.trace(e)); throw new DataExchangeException(e.getCause()); } return params; }
From source file:com.taobao.datax.plugins.reader.sqlserverreader.SqlServerReader.java
@Override public int startRead(LineSender sender) { if (null == this.connection) { logger.error("Connect to Sqlserver failed ."); return PluginStatus.FAILURE.value(); }/*from w w w .j av a2 s. c o m*/ DBResultSetSender proxy = DBResultSetSender.newSender(sender); proxy.setMonitor(this.getMonitor()); proxy.setDateFormatMap(this.getMapDateFormat()); logger.info(String.format("Execute sql %s .", this.sql)); ResultSet rs = null; try { rs = DBUtils.query(this.connection, sql); proxy.sendToWriter(rs); proxy.flush(); getMonitor().setStatus(PluginStatus.READ_OVER); return PluginStatus.SUCCESS.value(); } catch (SQLException e) { logger.error(ExceptionTracker.trace(e)); throw new DataExchangeException(e.getCause()); } finally { if (null != rs) { DBUtils.closeResultSet(rs); } } }
From source file:org.snaker.engine.access.jdbc.JdbcAccess.java
public <T> List<T> queryList(Class<T> clazz, String sql, Object... args) { try {/* w ww . j ava 2s . co m*/ if (log.isDebugEnabled()) { log.debug("?=\n" + sql); } return runner.query(getConnection(), sql, new BeanPropertyHandler<T>(clazz), args); } catch (SQLException e) { log.error(e.getMessage(), e); throw new SnakerException(e.getMessage(), e.getCause()); } }
From source file:org.snaker.engine.access.jdbc.JdbcAccess.java
public <T> T queryObject(Class<T> clazz, String sql, Object... args) { List<T> result = null;// w w w . j a va 2 s.com try { if (log.isDebugEnabled()) { log.debug("??=\n" + sql); } result = runner.query(getConnection(), sql, new BeanPropertyHandler<T>(clazz), args); return JdbcHelper.requiredSingleResult(result); } catch (SQLException e) { log.error(e.getMessage(), e); throw new SnakerException(e.getMessage(), e.getCause()); } }
From source file:com.qcloud.component.snaker.access.mybatis.MybatisAccess.java
public <T> List<T> queryList(Class<T> clazz, String sql, Object... args) { SqlSession sqlSession = getSession(); try {/* www.ja v a 2s. c o m*/ if (log.isDebugEnabled()) { log.debug("?=\n" + sql); } return runner.query(sqlSession.getConnection(), sql, new BeanPropertyHandler<T>(clazz), args); } catch (SQLException e) { log.error(e.getMessage(), e); throw new SnakerException(e.getMessage(), e.getCause()); } finally { SqlSessionUtils.closeSqlSession(sqlSession, getSqlSessionFactory()); } }
From source file:com.qcloud.component.snaker.access.mybatis.MybatisAccess.java
public <T> T queryObject(Class<T> clazz, String sql, Object... args) { SqlSession sqlSession = getSession(); List<T> result = null;//ww w. j a va 2s.com try { if (log.isDebugEnabled()) { log.debug("??=\n" + sql); } result = runner.query(sqlSession.getConnection(), sql, new BeanPropertyHandler<T>(clazz), args); return JdbcHelper.requiredSingleResult(result); } catch (SQLException e) { log.error(e.getMessage(), e); throw new SnakerException(e.getMessage(), e.getCause()); } finally { SqlSessionUtils.closeSqlSession(sqlSession, getSqlSessionFactory()); } }