List of usage examples for java.sql SQLException getMessage
public String getMessage()
From source file:com.gopivotal.cloudfoundry.test.core.DataSourceUtils.java
public String checkAccess(DataSource dataSource) { try {/*from ww w. ja v a 2 s. c om*/ Connection connection = dataSource.getConnection(); PreparedStatement selectOne = connection.prepareStatement(SELECT_ONE); selectOne.execute(); return "ok"; } catch (SQLException e) { return "failed with " + e.getMessage(); } }
From source file:com.company.controller.admin.StudentController.java
@RequestMapping(value = "/save", method = RequestMethod.POST) public String save(HttpServletRequest req) { try {/*from w w w .ja va 2 s . c o m*/ Student s = new Student(); s.setFirstName(req.getParameter("firstName")); s.setLastName(req.getParameter("lastName")); s.setEmail(req.getParameter("email")); s.setGender(req.getParameter("gender")); s.setContactNo(req.getParameter("contactNo")); try { DateFormat dob = new SimpleDateFormat("yyyy-mm-dd"); s.setDob(dob.parse(req.getParameter("dob"))); } catch (ParseException pe) { System.out.println(pe.getMessage()); } s.setStatus(req.getParameter("status") != null); if (req.getParameter("id") != null && req.getParameter("id").equals("0")) { //return s.toString(); studentService.insert(s); } else { s.setId(Integer.parseInt(req.getParameter("id"))); studentService.update(s); } } catch (SQLException se) { return se.getMessage(); } return "redirect:/admin/students"; }
From source file:co.nubetech.hiho.mapreduce.lib.db.apache.OracleDataDrivenDBInputFormat.java
@Override protected RecordReader<LongWritable, T> createDBRecordReader(DBInputSplit split, Configuration conf) throws IOException { DBConfiguration dbConf = getDBConf(); @SuppressWarnings("unchecked") Class<T> inputClass = (Class<T>) (dbConf.getInputClass()); try {/*from w w w.j a va2s. c o m*/ // Use Oracle-specific db reader return new OracleDataDrivenDBRecordReader<T>(split, inputClass, conf, getConnection(), dbConf, dbConf.getInputConditions(), dbConf.getInputFieldNames(), dbConf.getInputTableName()); } catch (SQLException ex) { throw new IOException(ex.getMessage()); } }
From source file:com.collabnet.ccf.core.db.MapTableUpdater.java
protected void initialiseReusablePreparedStatement() { try {/*from w w w.ja v a2 s . co m*/ reusablePreparedStatement = connection.prepareStatement(sql); } catch (SQLException e) { log.error("While creating an prepared statement, an error occured: " + e.getMessage()); } return; }
From source file:com.gs.obevo.db.impl.platforms.db2.Db2SqlExecutorTest.java
@Test public void testFindTableNameFromSQLException20054() { SQLException diagnosable = mock(SQLException.class); when(diagnosable.getMessage()) .thenReturn("DB2 SQL error: SQLCODE: -20054, SQLSTATE: 55019, SQLERRMC: MY_SCHEMA.MYTAB1_;23"); assertEquals(Tuples.pair(new PhysicalSchema("MY_SCHEMA"), "MYTAB1_"), this.executor.findTableNameFromException(diagnosable, -20054)); verify(diagnosable, times(1)).getMessage(); }
From source file:com.thoughtworks.go.server.persistence.MaterialRepositoryWithH2IntegrationTest.java
@Test @RunIf(value = DatabaseChecker.class, arguments = { DatabaseChecker.H2 }) public void shouldPreventInsertionOfMaterialsWithSameFingerprint() throws Exception { try {/*from w w w . j av a 2 s. com*/ dbHelper.execute( "INSERT into Materials(type, flyweightName, fingerprint) VALUES ('DependencyMaterial', 'bar', 'foo')"); dbHelper.execute( "INSERT into Materials(type, flyweightName, fingerprint) VALUES ('SvnMaterial', 'baz', 'foo')"); fail("should have failed"); } catch (SQLException passed) { assertThat(passed.getMessage(), containsString("Unique index or primary key violation")); assertThat(passed.getMessage(), containsString("PUBLIC.MATERIALS(FINGERPRINT)")); } }
From source file:TestAppletNetscape.java
public void destroy() { System.out.println("destroy(): closing connection for applet created at " + created.toString()); try {//from ww w .j av a 2 s. co m conn.close(); } catch (SQLException e) { System.err.println("destroy: SQLException: " + e.getMessage()); } }
From source file:com.googlecode.datasourcetester.server.DataSourceTesterServiceImpl.java
public String[][] queryDataSource(String dataSourceJndiName, String query) { Connection conn = null;//from www .ja va 2 s .c om try { InitialContext jndiContext = new InitialContext(); DataSource ds = (DataSource) jndiContext.lookup(dataSourceJndiName); conn = ds.getConnection(); PreparedStatement stmt = conn.prepareStatement(query); ResultSet rs = stmt.executeQuery(); ResultSetMetaData resMeta = rs.getMetaData(); LinkedList<String[]> rowList = new LinkedList<String[]>(); String[] colLabels = new String[resMeta.getColumnCount()]; for (int colNr = 1; colNr <= resMeta.getColumnCount(); colNr++) { colLabels[colNr - 1] = resMeta.getColumnName(colNr); } rowList.add(colLabels); while (rs.next()) { String[] rowData = new String[resMeta.getColumnCount()]; for (int colNr = 1; colNr <= resMeta.getColumnCount(); colNr++) { rowData[colNr - 1] = rs.getString(colNr); } rowList.add(rowData); } conn.close(); return rowList.toArray(new String[rowList.size()][]); } catch (Exception e) { logger.error(e.getMessage(), e); try { if (conn != null && !conn.isClosed()) { conn.close(); } } catch (SQLException sqlEx) { logger.error(sqlEx.getMessage(), sqlEx); } return null; } }
From source file:com.jaspersoft.jasperserver.remote.connection.JndiConnectionStrategy.java
@Override public JndiConnection createConnection(JndiConnection connectionDescription, Map<String, Object> data) throws IllegalParameterValueException { Connection conn = null;/*from w ww.ja v a2 s .c o m*/ boolean passed = false; Throwable exception = null; try { Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup("java:comp/env/" + connectionDescription.getJndiName()); conn = dataSource.getConnection(); if (conn != null) { passed = true; } } catch (SQLException vex) { if (vex.getMessage().indexOf("[JI_CONNECTION_VALID]") >= 0) passed = true; exception = vex; } catch (Throwable e) { exception = e; } finally { if (conn != null) try { conn.close(); } catch (SQLException e) { log.error("Couldn't disconnect JNDI connection", e); } } if (!passed) { throw new ConnectionFailedException(connectionDescription.getJndiName(), "jndiName", "Invalid JNDI name: " + connectionDescription.getJndiName(), exception); } return connectionDescription; }
From source file:com.alibaba.wasp.jdbc.TestJdbcConnectionPool.java
@Test public void testConnectionSize() throws SQLException { try {/*from www.jav a2 s. c o m*/ for (int i = 0; i < 5; i++) { Connection conn = pool.getConnection(); } } catch (SQLException e) { assertTrue(e.getMessage().indexOf("get connection timeout") != -1); } pool = JdbcConnectionPool.create(new JdbcDataSource(conf), conf); for (int i = 0; i < 5; i++) { Connection conn = pool.getConnection(); conn.close(); } }