List of usage examples for java.sql SQLException getLocalizedMessage
public String getLocalizedMessage()
From source file:uk.ac.ebi.phenotype.service.MaOntologyService.java
/** * Methods annotated with @PostConstruct are executed just after the constructor * is run and spring is initialised.//from w w w . j ava 2 s .co m * * @throws RuntimeException PostConstruct forbids throwing checked exceptions, * so SQLException is re-mapped to a RuntimeException if a failure occurs. */ @Override @PostConstruct public void initialize() throws RuntimeException { super.initialize(); try { populateSubsets(); } catch (SQLException e) { logger.error(e.getLocalizedMessage()); throw new RuntimeException(e); } }
From source file:org.apache.roller.weblogger.business.startup.SQLScriptRunner.java
/** Run script, logs messages, and optionally throws exception on error */ public void runScript(Connection con, boolean stopOnError) throws SQLException { failed = false;/*from www . jav a 2 s. c o m*/ errors = false; for (String command : commands) { // run each command try { Statement stmt = con.createStatement(); stmt.executeUpdate(command); if (!con.getAutoCommit()) { con.commit(); } // on success, echo command to messages successMessage(command); } catch (SQLException ex) { // add error message with text of SQL command to messages errorMessage("ERROR: SQLException executing SQL [" + command + "] : " + ex.getLocalizedMessage()); // add stack trace to messages StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); errorMessage(sw.toString()); if (stopOnError) { failed = true; throw ex; } } } }
From source file:com.rapidbackend.socialutil.install.dbinstall.SQLScriptRunner.java
/** Run script, logs messages, and optionally throws exception on error */ public void runScript(Connection con, boolean stopOnError) throws SQLException { failed = false;/*from w ww .jav a 2 s. c o m*/ errors = false; for (String command : commands) { // run each command try { Statement stmt = con.createStatement(); stmt.executeUpdate(command); if (!con.getAutoCommit()) con.commit(); // on success, echo command to messages successMessage(command); } catch (SQLException ex) { // add error message with text of SQL command to messages errorMessage("ERROR: SQLException executing SQL [" + command + "] : " + ex.getLocalizedMessage()); // add stack trace to messages StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); errorMessage(sw.toString()); if (stopOnError) { failed = true; throw ex; } } } }
From source file:salomon.engine.platform.data.tree.TreeManager.java
public ITree getTree(String name) throws PlatformException { // selecting Tree by name SQLSelect select = new SQLSelect(); select.addTable(TreeInfo.TABLE_NAME); select.addCondition("tree_name =", name); // to ensure solution_id consistency select.addCondition("solution_id =", _solutionInfo.getId()); ResultSet resultSet = null;/* www.j a v a2s.co m*/ ITree tree = null; try { resultSet = _dbManager.select(select); // WARNING! int treeID = 0; if (resultSet.next()) { treeID = resultSet.getInt("tree_id"); // assuming it exist, cause it was return by the query above (no multiuser access supported) tree = getTree(treeID); } } catch (SQLException e) { LOGGER.fatal("", e); throw new DBException(e.getLocalizedMessage()); } finally { try { _dbManager.closeResultSet(resultSet); } catch (SQLException e) { LOGGER.fatal("", e); throw new DBException(e.getLocalizedMessage()); } } return tree; }
From source file:com.freedomotic.plugins.devices.harvester_chart.HarvesterChart.java
@ListenEventsOn(channel = "app.event.sensor.object.behavior.clicked") public void onObjectClicked(EventTemplate event) { List<String> behavior_list = new ArrayList<String>(); System.out.println("received event " + event.toString()); ObjectReceiveClick clickEvent = (ObjectReceiveClick) event; //PRINT EVENT CONTENT WITH System.out.println(clickEvent.getPayload().toString()); String objectName = clickEvent.getProperty("object.name"); String protocol = clickEvent.getProperty("object.protocol"); String address = clickEvent.getProperty("object.address"); try {/*from ww w. ja v a2s. c om*/ Statement stat = connection.createStatement(); System.out.println("Protocol=" + protocol + ",Address=" + address); //for (EnvObjectLogic object : EnvObjectPersistence.getObjectByProtocol("wifi_id")){ //EnvObjectLogic object = EnvObjectPersistence.getObjectByName(objectName); for (EnvObjectLogic object : EnvObjectPersistence.getObjectByAddress(protocol, address)) { for (BehaviorLogic behavior : object.getBehaviors()) { System.out.println(behavior.getName()); } } //String query = "select date,value from events where protocol='"+clickEvent.getProperty("object.protocol")+"' and behavior='power' ORDER BY ID DESC LIMIT 1000;"; String query = "select date,value from events where object='" + objectName + "' and behavior='power' ORDER BY ID DESC LIMIT 1000;"; System.out.println(query); //String query = "select datetime(date, 'unixepoch', 'localtime') as TIME,value from events where protocol='remote_receiver' and behavior='button'"; ResultSet rs = stat.executeQuery(query); //JFreeChart chart = ChartFactory.createLineChart("Test", "Id", "Score", dataset, PlotOrientation.VERTICAL, true, true, false); //System.out.println("Wilson Kong Debug:"+rs.getLong("date")); final TimeSeries series = new TimeSeries("Data1", Millisecond.class); while (rs.next()) { Date resultdate = new Date(rs.getLong("date") * 1000); Millisecond ms_read = new Millisecond(resultdate); series.addOrUpdate(ms_read, rs.getDouble("value")); //series.add((Millisecond)rs.getLong("date"),(double)rs.getLong("value")); } XYDataset xyDataset = new TimeSeriesCollection(series); JFreeChart chart = ChartFactory.createTimeSeriesChart("Chart", "TIME", "VALVE", xyDataset, true, // legend true, // tooltips false // urls ); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(800, 500)); JFrame f = new JFrame("Chart"); f.setContentPane(chartPanel); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.pack(); f.setVisible(true); //if (...) { //MyFrame myFrame = new MyFrame(); //bindGuiToPlugin(myFrame); //showGui(); //triggers the showing of your frame. Before it calls onShowGui() //} } catch (SQLException ex) { Logger.getLogger(HarvesterChart.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage()); System.out.println("Wilson Kong Error: " + ex.toString()); //ex.printStackTrace(); stop(); } }
From source file:com.freedomotic.plugins.devices.harvester_chart.HarvesterChart.java
@Override public void onStart() { String dbType = configuration.getStringProperty("driver", "h2"); String dbUser = configuration.getStringProperty("dbuser", "sa"); String dbPassword = configuration.getStringProperty("dbpassword", ""); String dbName = configuration.getStringProperty("dbname", "harvester"); String driverClass = ""; try {/*from w w w. j a v a 2s. c om*/ String dbBasePath, dbPath; char shortDBType = 'z'; if ("h2".equals(dbType)) { shortDBType = 'h'; } if ("mysql".equals(dbType)) { shortDBType = 'm'; } if ("sqlserver".equals(dbType)) { shortDBType = 's'; } if ("sqlite".equals(dbType)) { shortDBType = 'l'; } //System.out.println("Wilson Kong Debug Message:" + dbType); switch (shortDBType) { case ('h'): dbBasePath = configuration.getStringProperty("dbpath", Info.getDevicesPath() + File.separator + "/es.gpulido.harvester/data"); dbPath = dbBasePath; driverClass = "org.h2.Driver"; break; case ('m'): dbBasePath = configuration.getStringProperty("dbpath", "localhost"); dbPath = "//" + dbBasePath; driverClass = "com.mysql.jdbc.Driver"; break; case ('s'): dbBasePath = configuration.getStringProperty("dbpath", "localhost"); dbPath = "//" + dbBasePath; driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; break; case ('l'): dbBasePath = configuration.getStringProperty("dbpath", Info.getDevicesPath() + File.separator + "es.gpulido.harvester" + File.separator + "data"); dbPath = dbBasePath + File.separator + dbName; driverClass = "org.sqlite.JDBC"; break; default: dbPath = ""; } //System.out.println("Wilson Kong Message: jdbc:" + dbType + ":" + dbPath + File.separator + dbName); Class.forName(driverClass); connection = DriverManager.getConnection("jdbc:" + dbType + ":" + dbPath, dbUser, dbPassword); // add application code here this.setDescription( "Connected to jdbc:" + dbType + ":" + dbPath + File.separator + dbName + " as user:" + dbUser); } catch (SQLException ex) { Logger.getLogger(HarvesterChart.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage()); System.out.println("Wilson Kong Error: " + ex.toString()); //ex.printStackTrace(); stop(); } catch (ClassNotFoundException ex) { Logger.getLogger(HarvesterChart.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage()); this.setDescription("The " + driverClass + " Driver is not loaded"); System.out.println("Wilson Kong Error: " + ex.toString()); stop(); } }
From source file:org.orbisgis.dbjobs.jobs.ImportFiles.java
@Override protected Object doInBackground() throws Exception { long deb = System.currentTimeMillis(); try (Connection connection = dataManager.getDataSource().getConnection()) { ProgressMonitor filePm = this.getProgressMonitor().startTask(files.size()); boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); for (File file : files) { String ext = FilenameUtils.getExtension(file.getName()); DriverFunction driverFunction = driverFunctionContainer.getImportDriverFromExt(ext, driverType); if (driverFunction != null) { String tableNameTest = TableLocation.capsIdentifier(FileUtils.getNameFromURI(file.toURI()), isH2);/*from ww w.j av a2 s.co m*/ if (tableNameTest == null) { tableNameTest = FileUtils.getNameFromURI(file.toURI()); } String tableName = dataManager .findUniqueTableName(new TableLocation("", schema, tableNameTest).toString(isH2)); driverFunction.importFile(connection, tableName, file, new H2GISProgressMonitor(filePm)); } else { LOGGER.error(I18N.tr("No driver found for {0} extension", ext)); } } } catch (SQLException ex) { LOGGER.error(I18N.tr("Cannot import the file.\nCause : {0}", ex.getMessage()), ex); // Print additional information while ((ex = ex.getNextException()) != null) { LOGGER.error(ex.getLocalizedMessage()); } } catch (IOException ex) { LOGGER.error(I18N.tr("Cannot import the file.\nCause : {0}", ex.getMessage()), ex); } LOGGER.info(I18N.tr("Importation done in {0} sec", (System.currentTimeMillis() - deb) / 1000d)); dbView.onDatabaseUpdate(DatabaseView.DB_ENTITY.SCHEMA.name(), "PUBLIC"); return null; }
From source file:com.ibm.research.rdf.store.jena.impl.DB2Dataset.java
public void commit() { try {/* w ww.j a v a 2s. co m*/ connection.commit(); } catch (SQLException e) { throw new RdfStoreException(e.getLocalizedMessage(), e); } }
From source file:org.pentaho.platform.plugin.action.sql.SQLExecute.java
public void addErrorCode(final MemoryResultSet affectedRowsResultSet, final SQLException e, final String failMsg) { int eCode = e.getErrorCode(); if (eCode > 0) { eCode *= -1; // Make sure that error code results are negative. }/*from w w w . jav a 2s . co m*/ affectedRowsResultSet.addRow(new Object[] { new Integer(eCode), e.getLocalizedMessage() }); }
From source file:org.orbisgis.geocatalog.impl.SourceListModel.java
/** * Constructor//from w w w . j a v a2s . com * @param dataManager * @note Do not forget to call dispose() */ public SourceListModel(DataManager dataManager) { this.dataSource = dataManager.getDataSource(); try (Connection connection = dataSource.getConnection()) { isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); } catch (SQLException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); } //Install database listeners dataManager.addDatabaseProgressionListener(this, StateEvent.DB_STATES.STATE_STATEMENT_END); //Call readDatabase when a SourceManager fire an event onDataManagerChange(); }