Java Code Examples for com.mysql.jdbc.Statement

The following are top voted examples for showing how to use com.mysql.jdbc.Statement. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: webpage-update-subscribe   File: ContentDAO.java   Source Code and License 6 votes vote down vote up
@Override
/**
 * @Title: doInsert
 * @Description: Insert a piece of new Content Info
 * @param content
 * @return boolean
 * @throws Exception
 */
public int doInsert(int UrlID, String Html, String Delta) throws Exception {
	String query = "insert into Content (UrlID,Html,Delta) values(?,?,?)";
	ps = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
	ps.setInt(1, UrlID);
	ps.setString(2, Html);
	ps.setString(3, Delta);
	if(ps.executeUpdate() == 0){
		ps.close();
		return -1;
	}
	ResultSet rs = ps.getGeneratedKeys();
	rs.next();
	int ContentID = rs.getInt(1);
	rs.close();ps.close();
	return ContentID;
}
 
Example 2
Project: webpage-update-subscribe   File: ContentDAO.java   Source Code and License 6 votes vote down vote up
@Override
/**
 * 
 * @Title: doFindAllChanged
 * @Description: ͨ查找所有更新了Delta的Content,返回Content的LinkedList
 * @return LinkedList<Content>
 * @throws Exception
 */
public LinkedList<Content> doFindAllChanged() throws Exception{
	String query = "select * from Content where Delta!=\"\"";
	Statement stat = (Statement) conn.createStatement();
	ResultSet rs = stat.executeQuery(query);
	LinkedList<Content> result = new LinkedList<Content>();
	while(rs.next()){
		Content newContent = new Content();
		newContent.setContentID(rs.getInt(1));
		newContent.setUrlID(rs.getInt(2));
		newContent.setHtml(rs.getString(3));
		newContent.setDelta(rs.getString(4));
		result.add(newContent);
	}
	rs.close();stat.close();		
	return result;
}
 
Example 3
Project: webpage-update-subscribe   File: UrlDAO.java   Source Code and License 6 votes vote down vote up
@Override
/**
 * 
 * @Title: doFindAllEnabledAndRealTimePush
 * @Description: 发现所有激活状态同时是实时推送的Url
 * @return Map<Integer, String>
 * @throws SQLException
 */
public Map<Integer, String> doFindAllEnabledAndRealTimePush() throws SQLException {
	String query = "select UrlID,UserName from Url where Enabled=true and RealTimePush=true";
	Statement stat = (Statement) conn.createStatement();
	ResultSet rs = stat.executeQuery(query);
	Map<Integer,String> urlMap= new HashMap<Integer,String>();
	while(rs.next()){
		int UrlID = rs.getInt(1);
		String UserName = rs.getString(2);
		urlMap.put(UrlID, UserName);
	}
	rs.close();stat.close();
	return urlMap;
}
 
Example 4
Project: webpage-update-subscribe   File: UrlDAO.java   Source Code and License 6 votes vote down vote up
@Override
/**
 * 
 * @Title: doFindAllEnabledAndNotRealTimePush
 * @Description: 发现所有不处于激活状态同时是实时推送的Url
 * @return Map<Integer, String>
 * @throws SQLException
 */
public Map<Integer, String> doFindAllEnabledAndNotRealTimePush() throws SQLException {
	String query = "select UrlID,UserName from Url where Enabled=true and RealTimePush=false";
	Statement stat = (Statement) conn.createStatement();
	ResultSet rs = stat.executeQuery(query);
	Map<Integer,String> urlMap= new HashMap<Integer,String>();
	while(rs.next()){
		int UrlID = rs.getInt(1);
		String UserName = rs.getString(2);
		urlMap.put(UrlID, UserName);
	}
	rs.close();stat.close();
	return urlMap;
}
 
Example 5
Project: webpage-update-subscribe   File: UrlDAO.java   Source Code and License 6 votes vote down vote up
@Override
/**
 * 
 * @Title: getAllUrl
 * @Description: ����Url��������������UrlID�Ͷ�ӦUrl��
 * @return Map<Integer,String>
 * @throws SQLException
 */
public Map<Integer,String> getAllUrl() throws SQLException {
	String query = "select UrlID,Url from Url where Enabled=true";
	Statement stat = (Statement) conn.createStatement();
	ResultSet rs = stat.executeQuery(query);
	Map<Integer,String> urlMap= new HashMap<Integer,String>();
	while(rs.next()){
		int UrlID = rs.getInt(1);
		String Url = rs.getString(2);
		urlMap.put(UrlID, Url);
	}
	rs.close();stat.close();
	return urlMap;
}
 
Example 6
Project: the-vigilantes   File: UtilsTest.java   Source Code and License 6 votes vote down vote up
/**
 * Tests Util.isJdbcInterface()
 * 
 * @throws Exception
 */
public void testIsJdbcInterface() throws Exception {
    // Classes directly or indirectly implementing JDBC interfaces.
    assertTrue(Util.isJdbcInterface(PreparedStatement.class));
    assertTrue(Util.isJdbcInterface(StatementImpl.class));
    assertTrue(Util.isJdbcInterface(Statement.class));
    assertTrue(Util.isJdbcInterface(ResultSetImpl.class));
    Statement s = (Statement) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { Statement.class }, new InvocationHandler() {
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return null;
        }
    });
    assertTrue(Util.isJdbcInterface(s.getClass()));

    // Classes not implementing JDBC interfaces.
    assertFalse(Util.isJdbcInterface(Util.class));
    assertFalse(Util.isJdbcInterface(UtilsTest.class));

}
 
Example 7
Project: the-vigilantes   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

    return null;
}
 
Example 8
Project: the-vigilantes   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

        if (stmt != null) {
            stmt.close();
        }
    }
}
 
Example 9
Project: OpenVertretung   File: UtilsTest.java   Source Code and License 6 votes vote down vote up
/**
 * Tests Util.isJdbcInterface()
 * 
 * @throws Exception
 */
public void testIsJdbcInterface() throws Exception {
    // Classes directly or indirectly implementing JDBC interfaces.
    assertTrue(Util.isJdbcInterface(PreparedStatement.class));
    assertTrue(Util.isJdbcInterface(StatementImpl.class));
    assertTrue(Util.isJdbcInterface(Statement.class));
    assertTrue(Util.isJdbcInterface(ResultSetImpl.class));
    Statement s = (Statement) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { Statement.class }, new InvocationHandler() {
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return null;
        }
    });
    assertTrue(Util.isJdbcInterface(s.getClass()));

    // Classes not implementing JDBC interfaces.
    assertFalse(Util.isJdbcInterface(Util.class));
    assertFalse(Util.isJdbcInterface(UtilsTest.class));

}
 
Example 10
Project: OpenVertretung   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

    return null;
}
 
Example 11
Project: OpenVertretung   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

        if (stmt != null) {
            stmt.close();
        }
    }
}
 
Example 12
Project: lams   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

    return null;
}
 
Example 13
Project: lams   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

        if (stmt != null) {
            stmt.close();
        }
    }
}
 
Example 14
Project: ProyectoPacientes   File: UtilsTest.java   Source Code and License 6 votes vote down vote up
/**
 * Tests Util.isJdbcInterface()
 * 
 * @throws Exception
 */
public void testIsJdbcInterface() throws Exception {
    // Classes directly or indirectly implementing JDBC interfaces.
    assertTrue(Util.isJdbcInterface(PreparedStatement.class));
    assertTrue(Util.isJdbcInterface(StatementImpl.class));
    assertTrue(Util.isJdbcInterface(Statement.class));
    assertTrue(Util.isJdbcInterface(ResultSetImpl.class));
    Statement s = (Statement) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { Statement.class }, new InvocationHandler() {
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return null;
        }
    });
    assertTrue(Util.isJdbcInterface(s.getClass()));

    // Classes not implementing JDBC interfaces.
    assertFalse(Util.isJdbcInterface(Util.class));
    assertFalse(Util.isJdbcInterface(UtilsTest.class));

}
 
Example 15
Project: ProyectoPacientes   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

    return null;
}
 
Example 16
Project: ProyectoPacientes   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

        if (stmt != null) {
            stmt.close();
        }
    }
}
 
Example 17
Project: BibliotecaPS   File: UtilsTest.java   Source Code and License 6 votes vote down vote up
/**
 * Tests Util.isJdbcInterface()
 * 
 * @throws Exception
 */
public void testIsJdbcInterface() throws Exception {
    // Classes directly or indirectly implementing JDBC interfaces.
    assertTrue(Util.isJdbcInterface(PreparedStatement.class));
    assertTrue(Util.isJdbcInterface(StatementImpl.class));
    assertTrue(Util.isJdbcInterface(Statement.class));
    assertTrue(Util.isJdbcInterface(ResultSetImpl.class));
    Statement s = (Statement) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { Statement.class }, new InvocationHandler() {
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return null;
        }
    });
    assertTrue(Util.isJdbcInterface(s.getClass()));

    // Classes not implementing JDBC interfaces.
    assertFalse(Util.isJdbcInterface(Util.class));
    assertFalse(Util.isJdbcInterface(UtilsTest.class));

}
 
Example 18
Project: BibliotecaPS   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

    return null;
}
 
Example 19
Project: BibliotecaPS   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

        if (stmt != null) {
            stmt.close();
        }
    }
}
 
Example 20
Project: AeroStory   File: MaplePet.java   Source Code and License 6 votes vote down vote up
public static int createPet(int itemid) {
    try {
        PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO pets (name, level, closeness, fullness, summoned) VALUES (?, 1, 0, 100, 0)", Statement.RETURN_GENERATED_KEYS);
        ps.setString(1, MapleItemInformationProvider.getInstance().getName(itemid));
        ps.executeUpdate();
        ResultSet rs = ps.getGeneratedKeys();
        int ret = -1;
        if (rs.next()) {
            ret = rs.getInt(1);
        }
        rs.close();
        ps.close();
        return ret;
    } catch (SQLException e) {
        return -1;
    }
}
 
Example 21
Project: AeroStory   File: MaplePet.java   Source Code and License 6 votes vote down vote up
public static int createPet(int itemid, byte level, int closeness, int fullness) {
    try {
        PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO pets (name, level, closeness, fullness, summoned) VALUES (?, ?, ?, ?, 0)", Statement.RETURN_GENERATED_KEYS);
        ps.setString(1, MapleItemInformationProvider.getInstance().getName(itemid));
        ps.setByte(2, level);
        ps.setInt(3, closeness);
        ps.setInt(4, fullness);
        ps.executeUpdate();
        ResultSet rs = ps.getGeneratedKeys();
        int ret = -1;
        if (rs.next()) {
            ret = rs.getInt(1);
            rs.close();
            ps.close();
        }
        return ret;
    } catch (SQLException e) {
        return -1;
    }
}
 
Example 22
Project: database   File: ItemDaoImpl.java   Source Code and License 6 votes vote down vote up
public void insert(Item item) {
	Connection connection = null;
	try {
		connection = dataSource.getConnection();
		PreparedStatement statement = connection.prepareStatement(SQL_INSERT, Statement.RETURN_GENERATED_KEYS);
		statement.setString(1, item.getName());
		statement.setLong(2, item.getWarehouse_id());
		statement.execute();
		
		ResultSet generatedkeys = statement.getGeneratedKeys();
		if (generatedkeys.next()) {
			item.setId(generatedkeys.getLong(1));
		}
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		dataSource.closeConnection(connection);
	}
}
 
Example 23
Project: database   File: WarehouseDaoImpl.java   Source Code and License 6 votes vote down vote up
public void insert(Warehouse warehouse) {
	Connection connection = null;
	try {
		connection = dataSource.getConnection();
		PreparedStatement statement = connection.prepareStatement(SQL_INSERT, Statement.RETURN_GENERATED_KEYS);
		statement.setString(1, warehouse.getAddress());
		statement.execute();
		
		ResultSet generatedkeys = statement.getGeneratedKeys();
		if (generatedkeys.next()) {
			warehouse.setId(generatedkeys.getLong(1));
		}
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		dataSource.closeConnection(connection);
	}
}
 
Example 24
Project: Geometry-wars   File: UtilsTest.java   Source Code and License 6 votes vote down vote up
/**
 * Tests Util.isJdbcInterface()
 * 
 * @throws Exception
 */
public void testIsJdbcInterface() throws Exception {
    // Classes directly or indirectly implementing JDBC interfaces.
    assertTrue(Util.isJdbcInterface(PreparedStatement.class));
    assertTrue(Util.isJdbcInterface(StatementImpl.class));
    assertTrue(Util.isJdbcInterface(Statement.class));
    assertTrue(Util.isJdbcInterface(ResultSetImpl.class));
    Statement s = (Statement) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { Statement.class }, new InvocationHandler() {
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return null;
        }
    });
    assertTrue(Util.isJdbcInterface(s.getClass()));

    // Classes not implementing JDBC interfaces.
    assertFalse(Util.isJdbcInterface(Util.class));
    assertFalse(Util.isJdbcInterface(UtilsTest.class));

}
 
Example 25
Project: Geometry-wars   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

    return null;
}
 
Example 26
Project: Geometry-wars   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

        if (stmt != null) {
            stmt.close();
        }
    }
}
 
Example 27
Project: TPKB   File: UtilsTest.java   Source Code and License 6 votes vote down vote up
/**
 * Tests Util.isJdbcInterface()
 * 
 * @throws Exception
 */
public void testIsJdbcInterface() throws Exception {
    // Classes directly or indirectly implementing JDBC interfaces.
    assertTrue(Util.isJdbcInterface(PreparedStatement.class));
    assertTrue(Util.isJdbcInterface(StatementImpl.class));
    assertTrue(Util.isJdbcInterface(Statement.class));
    assertTrue(Util.isJdbcInterface(ResultSetImpl.class));
    Statement s = (Statement) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { Statement.class }, new InvocationHandler() {
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return null;
        }
    });
    assertTrue(Util.isJdbcInterface(s.getClass()));

    // Classes not implementing JDBC interfaces.
    assertFalse(Util.isJdbcInterface(Util.class));
    assertFalse(Util.isJdbcInterface(UtilsTest.class));

}
 
Example 28
Project: TPKB   File: UtilsTest.java   Source Code and License 6 votes vote down vote up
/**
 * Tests Util.isJdbcPackage()
 * 
 * @throws Exception
 */
public void testGetImplementedInterfaces() throws Exception {
    Class<?>[] ifaces;
    ifaces = Util.getImplementedInterfaces(Statement.class);
    assertEquals(1, ifaces.length);
    assertEquals(ifaces[0], java.sql.Statement.class);

    ifaces = Util.getImplementedInterfaces(StatementImpl.class);
    assertEquals(1, ifaces.length);
    assertEquals(ifaces[0], Statement.class);

    ifaces = Util.getImplementedInterfaces(ConnectionImpl.class);
    assertEquals(3, ifaces.length);
    List<Class<?>> ifacesList = Arrays.asList(ifaces);
    for (Class<?> clazz : new Class<?>[] { MySQLConnection.class, Serializable.class, ConnectionProperties.class }) {
        assertTrue(ifacesList.contains(clazz));
    }
}
 
Example 29
Project: TPKB   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

    return null;
}
 
Example 30
Project: TPKB   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

        if (stmt != null) {
            stmt.close();
        }
    }
}
 
Example 31
Project: EndUserInteractioion_RequestResponse_Command   File: JavaSEProfileDB.java   Source Code and License 6 votes vote down vote up
public JavaSEProfileDB() {

		try {
			// this will load the MySQL driver, each DB has its own driver
			Class.forName("com.mysql.jdbc.Driver");

			// setup the connection with the DB.
			connect = DriverManager
					.getConnection("jdbc:mysql://localhost/feedback?"
							+ "user=root&password=root");
			// statements allow to issue SQL queries to the database
			statement = (Statement) connect.createStatement();
		} catch (Exception e) {
			System.err.println("Got an exception! ");
			System.err.println(e.getMessage());
		}

	}
 
Example 32
Project: DemocracIT-GreekCrawler   File: DB.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the db_status of a consultation from the db.
 *
 * @param curl - The consultation's url
 * @return - The consultation's db status
 * @throws java.sql.SQLException
 */
public static String GetConsultationStatus(String curl) throws SQLException {
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT completed FROM consultation WHERE consultation_url  = '" + curl + "';");
    int db_status = 0;
    if (rs.next()) {
        db_status = rs.getInt(1);
    }
    if (db_status == 2) {
        return "blue";
    } else if (db_status == 1) {
        return "red";
    } else {
        return "green";
    }
}
 
Example 33
Project: DemocracIT-GreekCrawler   File: DB.java   Source Code and License 6 votes vote down vote up
/**
 * Starts the crawler's activity log
 *
 * @param startTime - The start time of the crawling procedure
 * @return - The activity's log id
 * @throws java.sql.SQLException
 */
public static int LogCrawler(long startTime) throws SQLException {
    String insertLogSql = "INSERT INTO log.activities (module_id, start_date, end_date, status_id, message) VALUES (?,?,?,?,?)";
    PreparedStatement prepLogCrawlStatement = connection.prepareStatement(insertLogSql, Statement.RETURN_GENERATED_KEYS);
    prepLogCrawlStatement.setInt(1, 1);
    prepLogCrawlStatement.setTimestamp(2, new java.sql.Timestamp(startTime));
    prepLogCrawlStatement.setTimestamp(3, null);
    prepLogCrawlStatement.setInt(4, 1);
    prepLogCrawlStatement.setString(5, null);
    prepLogCrawlStatement.executeUpdate();
    ResultSet rsq = prepLogCrawlStatement.getGeneratedKeys();
    int crawlerId = 0;
    if (rsq.next()) {
        crawlerId = rsq.getInt(1);
    }
    prepLogCrawlStatement.close();
    return crawlerId;
}
 
Example 34
Project: cloudera-cli-scripts   File: UtilsTest.java   Source Code and License 6 votes vote down vote up
/**
 * Tests Util.isJdbcInterface()
 * 
 * @throws Exception
 */
public void testIsJdbcInterface() throws Exception {
    // Classes directly or indirectly implementing JDBC interfaces.
    assertTrue(Util.isJdbcInterface(PreparedStatement.class));
    assertTrue(Util.isJdbcInterface(StatementImpl.class));
    assertTrue(Util.isJdbcInterface(Statement.class));
    assertTrue(Util.isJdbcInterface(ResultSetImpl.class));
    Statement s = (Statement) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { Statement.class }, new InvocationHandler() {
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return null;
        }
    });
    assertTrue(Util.isJdbcInterface(s.getClass()));

    // Classes not implementing JDBC interfaces.
    assertFalse(Util.isJdbcInterface(Util.class));
    assertFalse(Util.isJdbcInterface(UtilsTest.class));

}
 
Example 35
Project: cloudera-cli-scripts   File: UtilsTest.java   Source Code and License 6 votes vote down vote up
/**
 * Tests Util.isJdbcPackage()
 * 
 * @throws Exception
 */
public void testGetImplementedInterfaces() throws Exception {
    Class<?>[] ifaces;
    ifaces = Util.getImplementedInterfaces(Statement.class);
    assertEquals(1, ifaces.length);
    assertEquals(ifaces[0], java.sql.Statement.class);

    ifaces = Util.getImplementedInterfaces(StatementImpl.class);
    assertEquals(1, ifaces.length);
    assertEquals(ifaces[0], Statement.class);

    ifaces = Util.getImplementedInterfaces(ConnectionImpl.class);
    assertEquals(3, ifaces.length);
    List<Class<?>> ifacesList = Arrays.asList(ifaces);
    for (Class<?> clazz : new Class<?>[] { MySQLConnection.class, Serializable.class, ConnectionProperties.class }) {
        assertTrue(ifacesList.contains(clazz));
    }
}
 
Example 36
Project: cloudera-cli-scripts   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

    return null;
}
 
Example 37
Project: cloudera-cli-scripts   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

        if (stmt != null) {
            stmt.close();
        }
    }
}
 
Example 38
Project: lBackup   File: DBMS_AbsolutePath.java   Source Code and License 6 votes vote down vote up
/**
 * insert new absolute path in the database
 * @param abs
 * @return
 */
public boolean insert(AbsolutePath abs){
	checkConnessione();
	try {
		sta = conn.createStatement();
		sta.execute("INSERT INTO absolute_path (path, type) VALUES ("
				+ "'" + abs.getPath() + "'," 
				+ abs.getType() 
				+ ")", Statement.RETURN_GENERATED_KEYS);
		
		res = sta.getGeneratedKeys();
		if(res.next()){
			abs.setId(res.getInt(1));
		}
		
		res.close();
		sta.close();
		conn.close();
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
}
 
Example 39
Project: fil_project_mgmt_app_v2   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql,
		Statement interceptedStatement, Connection connection)
		throws SQLException {
	String key = getSessionKey();
	
	if (key != null && !key.equals(this.currentSessionKey)) {
		PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");
		
		try {
			pstmt.setString(1, key);
			pstmt.execute();
		} finally {
			pstmt.close();
		}
		
		this.currentSessionKey = key;
	}
	
	return null;
}
 
Example 40
Project: fil_project_mgmt_app_v2   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods postProcess(String sql,
		Statement interceptedStatement,
		ResultSetInternalMethods originalResultSet, Connection connection)
		throws SQLException {

	if (connection.versionMeetsMinimum(5, 0, 2)) {
		populateMapWithSessionStatusValues(connection, this.postExecuteValues);

		connection.getLog().logInfo(
				"Server status change for statement:\n"
						+ Util.calculateDifferences(this.preExecuteValues,
								this.postExecuteValues));
	}

	return null; // we don't actually modify a result set

}
 
Example 41
Project: fil_project_mgmt_app_v2   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection,
		Map<String, String> toPopulate) throws SQLException {
	java.sql.Statement stmt = null;
	java.sql.ResultSet rs = null;

	try {
		toPopulate.clear();

		stmt = connection.createStatement();
		rs = stmt.executeQuery("SHOW SESSION STATUS");
		Util.resultSetToMap(toPopulate, rs);
	} finally {
		if (rs != null) {
			rs.close();
		}

		if (stmt != null) {
			stmt.close();
		}
	}
}
 
Example 42
Project: Sapient   File: ConnMysql.java   Source Code and License 6 votes vote down vote up
/**
 * 说明:用于执行插入、更新、删除的sql语句,当受影响的行数为0和执行失败时返回false
 * 
 * @param sql
 * @return boolean 成功返回true,失败返回false
 */
public boolean excSql(String sql) {
	if (con == null)
		getConnection(); // 连接到数据库

	try {
		Statement st = (Statement) con.createStatement(); // 创建用于执行静态sql语句的Statement对象
		int counts = st.executeUpdate(sql); // 执行操作的sql语句
		if (0 == counts) {
			log.info("执行成功,,共0条数据受到影响,没有完成操作!:SQL语句-->【" + sql + "】");
			return false;
		}
		log.info("执行成功,共" + counts + "条数据受到影响:" + "SQL语句-->【" + sql + "】");
		return true;
	} catch (SQLException e) {
		log.error("执行失败:SQL语句-->【" + sql + "】");
		log.error(e.getMessage());
		return false;
	}

}
 
Example 43
Project: pms   File: FieldDescriptionDAOImpl.java   Source Code and License 6 votes vote down vote up
Integer insertIndent(Indent indent) throws SQLException{

		Integer generatedIndentId = null;

		String indentDescSql = "INSERT INTO Indent (ProjId, StartDate, EndDate, LastUpdatedBy, LastUpdatedAt) "
				+ "VALUES (?, ?, ?, ?, ?)";

		Connection connection = jdbcTemplate.getDataSource().getConnection();
		PreparedStatement preparedStatement = connection.prepareStatement(indentDescSql, Statement.RETURN_GENERATED_KEYS);

		preparedStatement.setString(1, indent.getProjId());
		preparedStatement.setString(2, indent.getStartDate());
		preparedStatement.setString(3, indent.getEndDate());
		preparedStatement.setString(4, indent.getEmployeeId());
		preparedStatement.setDate(5, new java.sql.Date(Calendar.getInstance().getTime().getTime()));

		preparedStatement.executeUpdate();
		ResultSet keys = preparedStatement.getGeneratedKeys();

		if (keys.next()) {
			generatedIndentId = keys.getInt(1); //id returned after insert execution
		} 

		return generatedIndentId;

	}
 
Example 44
Project: pms   File: FieldDescriptionDAOImpl.java   Source Code and License 6 votes vote down vote up
Integer insertIndentDesc(Integer indentId, IndentDesc indentDesc) throws SQLException{

		Integer generatedIndentDescId = null;
		
		String indentDescSql = "INSERT INTO IndentDesc (IndentId, ProjDescId, Quantity, Metric, Comments)"
				+ "VALUES (?, ?, ?, ?, ?)";

		Connection connection = jdbcTemplate.getDataSource().getConnection();
		PreparedStatement preparedStatement = connection.prepareStatement(indentDescSql, Statement.RETURN_GENERATED_KEYS);

		preparedStatement.setString(1, indentId.toString());
		preparedStatement.setString(2, indentDesc.getProjDescId());
		preparedStatement.setDouble(3, indentDesc.getPlannedQty());
		preparedStatement.setString(4, indentDesc.getMetric());
		preparedStatement.setString(5, indentDesc.getComments());

		preparedStatement.executeUpdate();
		ResultSet keys = preparedStatement.getGeneratedKeys();

		if (keys.next()) {
			generatedIndentDescId = keys.getInt(1); //id returned after insert execution
		} 

		return generatedIndentDescId;
	}
 
Example 45
Project: NE-Project   File: UserDAO.java   Source Code and License 6 votes vote down vote up
public void getUsers(){
	Connection connessione = null;
	ResultSet rs ;
	String risf;
	try{
		connessione = this.getConnection();
		String query2 = "SELECT DATA,USERNAME FROM users;";
		Statement qry = (Statement) connessione.prepareStatement(query2);	
		rs=qry.executeQuery(query2);
		int numRecord=0;
		while( rs.next() ){
			numRecord++;
			String u=rs.getString("USERNAME");
			java.sql.Date dataCreazione=rs.getDate("DATA");
			System.out.println(u+"\t\tCreato il "+dataCreazione);
		}
		System.out.println("Record letti:"+numRecord);
		rs.close();

	} catch (Exception ex) {
		System.out.println("SQLException: "+ ex.getMessage());
	}
}
 
Example 46
Project: indoor-tracking   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql,
		Statement interceptedStatement, Connection connection)
		throws SQLException {
	String key = getSessionKey();
	
	if (key != null && !key.equals(this.currentSessionKey)) {
		PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");
		
		try {
			pstmt.setString(1, key);
			pstmt.execute();
		} finally {
			pstmt.close();
		}
		
		this.currentSessionKey = key;
	}
	
	return null;
}
 
Example 47
Project: indoor-tracking   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods postProcess(String sql,
		Statement interceptedStatement,
		ResultSetInternalMethods originalResultSet, Connection connection)
		throws SQLException {

	if (connection.versionMeetsMinimum(5, 0, 2)) {
		populateMapWithSessionStatusValues(connection, this.postExecuteValues);

		connection.getLog().logInfo(
				"Server status change for statement:\n"
						+ Util.calculateDifferences(this.preExecuteValues,
								this.postExecuteValues));
	}

	return null; // we don't actually modify a result set

}
 
Example 48
Project: indoor-tracking   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection,
		Map<String, String> toPopulate) throws SQLException {
	java.sql.Statement stmt = null;
	java.sql.ResultSet rs = null;

	try {
		toPopulate.clear();

		stmt = connection.createStatement();
		rs = stmt.executeQuery("SHOW SESSION STATUS");
		Util.resultSetToMap(toPopulate, rs);
	} finally {
		if (rs != null) {
			rs.close();
		}

		if (stmt != null) {
			stmt.close();
		}
	}
}
 
Example 49
Project: SMPT42   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

    return null;
}
 
Example 50
Project: SMPT42   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

        if (stmt != null) {
            stmt.close();
        }
    }
}
 
Example 51
Project: ForYou   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql,
		Statement interceptedStatement, Connection connection)
		throws SQLException {
	String key = getSessionKey();
	
	if (key != null && !key.equals(this.currentSessionKey)) {
		PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");
		
		try {
			pstmt.setString(1, key);
			pstmt.execute();
		} finally {
			pstmt.close();
		}
		
		this.currentSessionKey = key;
	}
	
	return null;
}
 
Example 52
Project: ForYou   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods postProcess(String sql,
		Statement interceptedStatement,
		ResultSetInternalMethods originalResultSet, Connection connection)
		throws SQLException {

	if (connection.versionMeetsMinimum(5, 0, 2)) {
		populateMapWithSessionStatusValues(connection, this.postExecuteValues);

		connection.getLog().logInfo(
				"Server status change for statement:\n"
						+ Util.calculateDifferences(this.preExecuteValues,
								this.postExecuteValues));
	}

	return null; // we don't actually modify a result set

}
 
Example 53
Project: ForYou   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection,
		Map<String, String> toPopulate) throws SQLException {
	java.sql.Statement stmt = null;
	java.sql.ResultSet rs = null;

	try {
		toPopulate.clear();

		stmt = connection.createStatement();
		rs = stmt.executeQuery("SHOW SESSION STATUS");
		Util.resultSetToMap(toPopulate, rs);
	} finally {
		if (rs != null) {
			rs.close();
		}

		if (stmt != null) {
			stmt.close();
		}
	}
}
 
Example 54
Project: group-five   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

    return null;
}
 
Example 55
Project: group-five   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

        if (stmt != null) {
            stmt.close();
        }
    }
}
 
Example 56
Project: locaviewer   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

    return null;
}
 
Example 57
Project: locaviewer   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

        if (stmt != null) {
            stmt.close();
        }
    }
}
 
Example 58
Project: locaviewer   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

    return null;
}
 
Example 59
Project: locaviewer   File: ServerStatusDiffInterceptor.java   Source Code and License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

        if (stmt != null) {
            stmt.close();
        }
    }
}
 
Example 60
Project: manydesigns.cn   File: SessionAssociationInterceptor.java   Source Code and License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql,
		Statement interceptedStatement, Connection connection)
		throws SQLException {
	String key = getSessionKey();
	
	if (key != null && !key.equals(this.currentSessionKey)) {
		PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");
		
		try {
			pstmt.setString(1, key);
			pstmt.execute();
		} finally {
			pstmt.close();
		}
		
		this.currentSessionKey = key;
	}
	
	return null;
}