Java Code Examples for java.sql.SQLException.getMessage()

The following are Jave code examples for showing how to use getMessage() of the java.sql.SQLException class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: asura   File: JobStoreSupport.java   View Source Code Vote up 6 votes
/**
 * <p>
 * Pause all triggers - equivalent of calling <code>pauseTriggerGroup(group)</code>
 * on every group.
 * </p>
 * 
 * <p>
 * When <code>resumeAll()</code> is called (to un-pause), trigger misfire
 * instructions WILL be applied.
 * </p>
 * 
 * @see #resumeAll(SchedulingContext)
 * @see #pauseTriggerGroup(SchedulingContext, String)
 */
public void pauseAll(Connection conn, SchedulingContext ctxt)
    throws JobPersistenceException {

    String[] names = getTriggerGroupNames(conn, ctxt);

    for (int i = 0; i < names.length; i++) {
        pauseTriggerGroup(conn, ctxt, names[i]);
    }

    try {
        if (!getDelegate().isTriggerGroupPaused(conn, ALL_GROUPS_PAUSED)) {
            getDelegate().insertPausedTriggerGroup(conn, ALL_GROUPS_PAUSED);
        }

    } catch (SQLException e) {
        throw new JobPersistenceException(
                "Couldn't pause all trigger groups: " + e.getMessage(), e);
    }

}
 
Example 2
Project: spwrap   File: DbUtilsResultSetAutoMapper.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
public T map(Result<?> result) {

    ResultSet rs = (ResultSet) result.wrappedObject();

    try {
        if (rs.getMetaData().getColumnCount() == 1){
            // same code as org.apache.commons.dbutils.handlers.ScalarHandler
            // (cannot reuse the object as it calls rs.next())
            return (T) rs.getObject(1);
        }else {
            return beanProcessor.toBean(rs, getType());
        }

    } catch (SQLException e) {
        throw new CallException(e.getMessage(), e);
    }
}
 
Example 3
Project: HR-Management-System-in-Java-using-swing-framework   File: DailyTaskHandling.java   View Source Code Vote up 6 votes
public static boolean Load() 
{
     if(!dailylist.isEmpty())
        return false;
    ResultSet resultSet = ConnectionClass.selectQuery("select * from dailywork;");
    try{
        while(resultSet.next()){
        dailylist.add(new DailyTask(Integer.parseInt(resultSet.getObject(1).toString()), 
                resultSet.getObject(2).toString(), 
                resultSet.getObject(3).toString(), 
                resultSet.getString(4), 
                resultSet.getString(5)));
        }
        System.out.println("loaded with size of " + dailylist.size());
    }catch(SQLException e){
        e.getMessage();
    }
    return true;
    
  }
 
Example 4
Project: ProyectoPacientes   File: MysqlDataSource.java   View Source Code Vote up 6 votes
/**
 * Required method to support this class as a <CODE>Referenceable</CODE>.
 * 
 * @return a Reference to this data source
 * 
 * @throws NamingException
 *             if a JNDI error occurs
 */
public Reference getReference() throws NamingException {
    String factoryName = "com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory";
    Reference ref = new Reference(getClass().getName(), factoryName, null);
    ref.add(new StringRefAddr(NonRegisteringDriver.USER_PROPERTY_KEY, getUser()));
    ref.add(new StringRefAddr(NonRegisteringDriver.PASSWORD_PROPERTY_KEY, this.password));
    ref.add(new StringRefAddr("serverName", getServerName()));
    ref.add(new StringRefAddr("port", "" + getPort()));
    ref.add(new StringRefAddr("databaseName", getDatabaseName()));
    ref.add(new StringRefAddr("url", getUrl()));
    ref.add(new StringRefAddr("explicitUrl", String.valueOf(this.explicitUrl)));

    //
    // Now store all of the 'non-standard' properties...
    //
    try {
        storeToRef(ref);
    } catch (SQLException sqlEx) {
        throw new NamingException(sqlEx.getMessage());
    }

    return ref;
}
 
Example 5
Project: ChronoBike   File: DbPreparedStatement.java   View Source Code Vote up 6 votes
private int execute()
{
	if(m_PreparedStatement != null)
	{
		try
		{
			boolean b = m_PreparedStatement.execute();
			if(b)
				return 1;
		}
		catch (SQLException e)
		{
			Log.logCritical("SQL execute error: "+e.getMessage());
			throw new RuntimeException("SQL execute error: "+e.getMessage(),e);
		}
	}
	return -1;		
}
 
Example 6
Project: ProyectoPacientes   File: ResultSetRegressionTest.java   View Source Code Vote up 6 votes
/**
 * Checks fix for BUG#1592 -- cross-database updatable result sets are not
 * checked for updatability correctly.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testFixForBug1592() throws Exception {
    if (versionMeetsMinimum(4, 1)) {
        Statement updatableStmt = this.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

        try {
            updatableStmt.execute("SELECT * FROM mysql.user");

            this.rs = updatableStmt.getResultSet();
        } catch (SQLException sqlEx) {
            String message = sqlEx.getMessage();

            if ((message != null) && (message.indexOf("denied") != -1)) {
                System.err.println("WARN: Can't complete testFixForBug1592(), access to 'mysql' database not allowed");
            } else {
                throw sqlEx;
            }
        }
    }
}
 
Example 7
Project: AdvancedDataProfilingSeminar   File: SqlInputIterator.java   View Source Code Vote up 6 votes
@Override
public boolean next() throws InputIterationException {
	try {
		boolean hasNext = this.resultSet.next();
		
		if (hasNext) {
			int numColumns = this.resultSet.getMetaData().getColumnCount();
			this.record = new ArrayList<>(numColumns);
			
			for (int columnIndex = 1; columnIndex <= numColumns; columnIndex++) {
				String value = this.resultSet.getString(columnIndex);
				
				// Replace line breaks with the zero-character, because these line breaks would otherwise split values when later written to plane-text buckets
				if (value != null)
					value = value.replaceAll("\n", "\0");
				this.record.add(value);
			}
		}
		
		return hasNext;
	}
	catch (SQLException e) {
		e.printStackTrace();
		throw new InputIterationException(e.getMessage());
	}
}
 
Example 8
Project: ChronoBike   File: DbPreparedStatement.java   View Source Code Vote up 5 votes
public void setColParam(int nCol, int nValue)
{
	try
	{
		m_PreparedStatement.setInt(nCol+1, nValue);
	} 
	catch (SQLException e)
	{
		throw new RuntimeException("Could not set columnn "+String.valueOf(nCol)+" to value '"+String.valueOf(nValue)+"': "+e.getMessage(),e);
	}
}
 
Example 9
Project: spanner-jdbc   File: AbstractCloudSpannerConnection.java   View Source Code Vote up 5 votes
@Override
public void setClientInfo(Properties properties) throws SQLClientInfoException
{
	try
	{
		checkClosed();
	}
	catch (SQLException e)
	{
		throw new SQLClientInfoException(e.getMessage(), Collections.emptyMap());
	}
	// silently ignore
}
 
Example 10
Project: dev-courses   File: TestOdbcTypes.java   View Source Code Vote up 5 votes
public void testSecIntervalSimpleRead() {
    /* Since our client does not support the INTERVAL precision
     * constraints, the returned value will always be toString()'d to
     * precision of microseconds. */
    ResultSet rs = null;
    Statement st = null;
    try {
        st = netConn.createStatement();
        rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");
        assertTrue("Got no rows with id in (1, 2)", rs.next());
        assertEquals("1000.345000", rs.getString("sival"));
        assertTrue("Got only one row with id in (1, 2)", rs.next());
        // Can't test the class, because jdbc:odbc or the driver returns
        // a String for getObject() for interval values.
        assertFalse("Got too many rows with id in (1, 2)", rs.next());
    } catch (SQLException se) {
        junit.framework.AssertionFailedError ase
            = new junit.framework.AssertionFailedError(se.getMessage());
        ase.initCause(se);
        throw ase;
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (st != null) {
                st.close();
            }
        } catch(Exception e) {
        }
    }
}
 
Example 11
Project: ofmeet-openfire-plugin   File: SipAccountDAO.java   View Source Code Vote up 5 votes
public static void update(SipAccount sipAccount) throws SQLException {

		String sql = "UPDATE ofSipUser SET sipusername = ?, sipauthuser = ?, sipdisplayname = ?, sippassword = ?, sipserver = ?, enabled = ?, status = ?, stunserver = ?, stunport = ?, usestun = ?, voicemail= ?, outboundproxy = ?, promptCredentials = ? "
				+ " WHERE username = ?";

		Connection con = null;
		PreparedStatement psmt = null;

		try {

			con = DbConnectionManager.getConnection();
			psmt = con.prepareStatement(sql);
			psmt.setString(1, sipAccount.getSipUsername());
			psmt.setString(2, sipAccount.getAuthUsername());
			psmt.setString(3, sipAccount.getDisplayName());
			psmt.setString(4, sipAccount.getPassword());
			psmt.setString(5, sipAccount.getServer());
			psmt.setInt(6, sipAccount.isEnabled() ? 1 : 0);
			psmt.setString(7, sipAccount.getStatus().name());
			psmt.setString(8, sipAccount.getStunServer());
			psmt.setString(9, sipAccount.getStunPort());
			psmt.setInt(10, sipAccount.isUseStun() ? 1 : 0);
            psmt.setString(11, sipAccount.getVoiceMailNumber());
            psmt.setString(12, sipAccount.getOutboundproxy());
            psmt.setInt(13, sipAccount.isPromptCredentials() ? 1 : 0);
            psmt.setString(14, sipAccount.getUsername());

            psmt.executeUpdate();

		} catch (SQLException e) {
			Log.error(e.getMessage(), e);
			throw new SQLException(e.getMessage());
		} finally {
			DbConnectionManager.closeConnection(psmt, con);
		}

	}
 
Example 12
Project: asura   File: JobStoreSupport.java   View Source Code Vote up 5 votes
/**
 * <p>
 * Check existence of a given trigger.
 * </p>
 */
protected boolean triggerExists(Connection conn, String triggerName,
        String groupName) throws JobPersistenceException {
    try {
        return getDelegate().triggerExists(conn, triggerName, groupName);
    } catch (SQLException e) {
        throw new JobPersistenceException(
                "Couldn't determine trigger existence (" + groupName + "."
                        + triggerName + "): " + e.getMessage(), e);
    }
}
 
Example 13
Project: dev-courses   File: TestOdbcTypes.java   View Source Code Vote up 5 votes
public void testBooleanComplex() {
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        ps = netConn.prepareStatement(
            "INSERT INTO alltypes(id, b) VALUES(?, ?)");
        ps.setInt(1, 3);
        ps.setBoolean(2, false);
        assertEquals(1, ps.executeUpdate());
        ps.setInt(1, 4);
        assertEquals(1, ps.executeUpdate());
        ps.close();
        netConn.commit();
        ps = netConn.prepareStatement(
            "SELECT * FROM alltypes WHERE b = ?");
        ps.setBoolean(1, false);
        rs = ps.executeQuery();
        assertTrue("Got no rows with b = false", rs.next());
        assertEquals(Boolean.class, rs.getObject("b").getClass());
        assertTrue("Got only one row with b = false", rs.next());
        assertEquals(false, rs.getBoolean("b"));
        assertFalse("Got too many rows with b = false", rs.next());
    } catch (SQLException se) {
        junit.framework.AssertionFailedError ase
            = new junit.framework.AssertionFailedError(se.getMessage());
        ase.initCause(se);
        throw ase;
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (ps != null) {
                ps.close();
            }
        } catch(Exception e) {
        }
    }
}
 
Example 14
Project: dev-courses   File: TestOdbcTypes.java   View Source Code Vote up 5 votes
public void testDerivedStringSimpleRead() {
    ResultSet rs = null;
    Statement st = null;
    try {
        st = netConn.createStatement();
        rs = st.executeQuery("SELECT i, cv || 'appendage' app, 4\n"
                + "FROM alltypes WHERE id in (1, 2)");
        assertTrue("Got no rows with id in (1, 2)", rs.next());
        assertEquals(String.class, rs.getObject("app").getClass());
        assertTrue("Got only one row with id in (1, 2)", rs.next());
        assertEquals("cdappendage", rs.getString("app"));
        assertFalse("Got too many rows with id in (1, 2)", rs.next());
    } catch (SQLException se) {
        junit.framework.AssertionFailedError ase
            = new junit.framework.AssertionFailedError(se.getMessage());
        ase.initCause(se);
        throw ase;
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (st != null) {
                st.close();
            }
        } catch(Exception e) {
        }
    }
}
 
Example 15
Project: OpenVertretung   File: LoadBalancedConnectionProxy.java   View Source Code Vote up 5 votes
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    SQLException exceptionToThrow = SQLError.createSQLException(Messages.getString("LoadBalancedConnectionProxy.unusableConnection"),
            SQLError.SQL_STATE_INVALID_TRANSACTION_STATE, MysqlErrorNumbers.ERROR_CODE_NULL_LOAD_BALANCED_CONNECTION, true, null);
    Class<?>[] declaredException = method.getExceptionTypes();
    for (Class<?> declEx : declaredException) {
        if (declEx.isAssignableFrom(exceptionToThrow.getClass())) {
            throw exceptionToThrow;
        }
    }
    throw new IllegalStateException(exceptionToThrow.getMessage(), exceptionToThrow);
}
 
Example 16
Project: parabuild-ci   File: TransferDb.java   View Source Code Vote up 5 votes
boolean getAutoCommit() throws DataAccessPointException {

        boolean result = false;

        try {
            result = conn.getAutoCommit();
        } catch (SQLException e) {
            throw new DataAccessPointException(e.getMessage());
        }

        return result;
    }
 
Example 17
Project: parabuild-ci   File: TestUtil.java   View Source Code Vote up 4 votes
protected boolean test(Statement aStatement) {

        try {

            //execute the SQL
            try {
                aStatement.execute(getSql());
            } catch (SQLException s) {
                throw new Exception("Expected a ResultSet containing "
                                    + getCountWeWant()
                                    + " rows, but got the error: "
                                    + s.getMessage());
            }

            //check that update count != -1
            if (aStatement.getUpdateCount() != -1) {
                throw new Exception(
                    "Expected a ResultSet, but got an update count of "
                    + aStatement.getUpdateCount());
            }

            //iterate over the ResultSet
            ResultSet results = aStatement.getResultSet();
            int       count   = 0;

            while (results.next()) {
                count++;
            }

            //check that we got as many rows as expected
            if (count != getCountWeWant()) {

                //we don't have the expected number of rows
                throw new Exception("Expected the ResultSet to contain "
                                    + getCountWeWant()
                                    + " rows, but it contained " + count
                                    + " rows.");
            }
        } catch (Exception x) {
            message = x.getMessage();

            return false;
        }

        return true;
    }
 
Example 18
Project: parabuild-ci   File: TestUtil.java   View Source Code Vote up 4 votes
protected boolean test(Statement aStatement) {

        try {

            //execute the SQL
            try {
                aStatement.execute(getSql());
            } catch (SQLException s) {
                throw new Exception("Expected a ResultSet containing "
                                    + getCountWeWant()
                                    + " rows, but got the error: "
                                    + s.getMessage());
            }

            //check that update count != -1
            if (aStatement.getUpdateCount() != -1) {
                throw new Exception(
                    "Expected a ResultSet, but got an update count of "
                    + aStatement.getUpdateCount());
            }

            //iterate over the ResultSet
            ResultSet results = aStatement.getResultSet();
            int       count   = 0;

            while (results.next()) {
                count++;
            }

            //check that we got as many rows as expected
            if (count != getCountWeWant()) {

                //we don't have the expected number of rows
                throw new Exception("Expected the ResultSet to contain "
                                    + getCountWeWant()
                                    + " rows, but it contained " + count
                                    + " rows.");
            }
        } catch (Exception x) {
            message = x.getMessage();

            return false;
        }

        return true;
    }
 
Example 19
Project: OpenVertretung   File: ResultSetRegressionTest.java   View Source Code Vote up 3 votes
private void checkUpdatabilityMessage(SQLException sqlEx, String messageToCheck) throws Exception {

        String message = sqlEx.getMessage();

        assertNotNull(message);

        String localizedMessage = Messages.getString(messageToCheck);

        assertTrue("Didn't find required message component '" + localizedMessage + "', instead found:\n\n" + message, message.indexOf(localizedMessage) != -1);
    }
 
Example 20
Project: aaden-pay   File: DataBaseAccessException.java   View Source Code Vote up 2 votes
/**
 * Constructor for PangoSqlException.
 * 
 * @param task
 *            name of current task
 * @param sql
 *            the offending SQL statement
 * @param ex
 *            the root cause
 */
public DataBaseAccessException(String task, String sql, SQLException ex) {
	super(task + "SQLException for SQL [" + sql + "]; SQL state [" + ex.getSQLState() + "]; error code ["
			+ ex.getErrorCode() + "]; " + ex.getMessage(), ex);
	this.sql = sql;
}