Java Code Examples for com.mysql.jdbc.Connection#createStatement()

The following examples show how to use com.mysql.jdbc.Connection#createStatement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public User register(String username,String password,String level) {
	Connection conn = DBUtils.getConnection();
	User user = null;
	
	try {
		//判断数据库中是否存在该用户
		if(!userIsExist(username)){//不存在该用户,可以注册
			user = new User();//实例化一个user对象
			//给用户对象赋值
			user.setUsername(username);
			user.setPassword(password);
			user.setLevel(level);
			//将用户对象写入数据库
			Statement stmt = (Statement) conn.createStatement();
			stmt.executeUpdate("insert into user values('"+username+"','"+password+"','"+level+"');");
			stmt.close();//释放资源
		}
	} catch (Exception e) {
		e.printStackTrace();
	}finally {
		DBUtils.closeConnection(conn);
	}
	return user;
}
 
Example 2
Source File: ServerStatusDiffInterceptor.java    From r-course with MIT 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 3
Source File: ServerStatusDiffInterceptor.java    From Komondor with GNU General Public License v3.0 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();
        }
    }
}