Unable to get results from H2 db

I'm trying to get values from h2 db, but always getting this error

 org.h2.jdbc.JdbcSQLException: No data is available [2000-171]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
    at org.h2.message.DbException.get(DbException.java:169)
    at org.h2.message.DbException.get(DbException.java:146)
    at org.h2.message.DbException.get(DbException.java:135)
    at org.h2.jdbc.JdbcResultSet.checkOnValidRow(JdbcResultSet.java:2956)
    at org.h2.jdbc.JdbcResultSet.get(JdbcResultSet.java:2962)
    at org.h2.jdbc.JdbcResultSet.getInt(JdbcResultSet.java:306)

I googled for an answer

Make sure to call rs.next(); prior to using any of the getter methods.

But I do call rs.next() ...

Here's my code:

public User getUser(int userId) throws SQLException {
    User u = new User(userId);

    try {
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery("SELECT * FROM invited_users WHERE user_id=" + userId);


    } catch (SQLException except) {
        JOptionPane.showMessageDialog(null, "Unable to load user! " + except);
    return u;


The problem was in resultset, it was empty.

Just replace this code




if (rs.next()) {

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

  • Issue with heredoc and PHP
    I am following The book "Beginning PHP, Apache, MySQL web development" by Wrox. I have been following it verbatim and for some reason I am having a issue with the code. The editor says that there are no errors in my code. but when I run it gives me the following message: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3" here is the following code <?php //take in the id of a director and return his/her full name function get_director() { global $db; $query = 'SELECT people_fullname FROM people
  • Heredoc 和 PHP 的问题(Issue with heredoc and PHP)
    问题 我正在关注 Wrox 的“开始 PHP、Apache、MySQL Web 开发”一书。 我一直在逐字跟踪它,出于某种原因,我遇到了代码问题。 编辑器说我的代码中没有错误。 但是当我运行它时,它给了我以下消息:“您的 SQL 语法有错误;请检查与您的 MySQL 服务器版本相对应的手册,以获取在第 3 行附近使用的正确语法”这里是以下代码 <?php //take in the id of a director and return his/her full name function get_director() { global $db; $query = 'SELECT people_fullname FROM people WHERE people_id = ' . $director_id; $result = mysql_query($query, $db) or die(mysql_error($db)); $row = mysql_fetch_assoc($result); extract($row); return $people_fullname; } //take in the id of a lead actor and return his/her full name function get_leadactor($leadactor_id) {
  • Spring Boot /h2-console throws 403 with Spring Security 1.5.2
    We recently upgraded from Spring Boot 1.4.1 to 1.5.2. One of the features of 1.5.2 is that if Spring Security is part of the package then it is protected by basic auth. I am unable to access the /h2-console even after basic auth. It throws 403 forbidden. application.yml: spring: datasource: driver-class-name: org.h2.Driver url: jdbc:h2:file:../app-db/app_db;AUTO_SERVER=TRUE username: sa password: sa initialize: false jpa: hibernate: ddl-auto: validate show-sql: true database-platform: org.hibernate.dialect.H2Dialect h2: console: enabled: true settings: web-allow-others: true allowed: resources
  • 带有超链接的PHP / MySQL表(PHP/MySQL Table with Hyperlinks)
    问题 我有2个PHP表格。 一个显示事件列表,另一个显示每个特定事件的结果。 在具有事件列表的页面上,我希望这样做,以便可以创建超链接来访问每个事件的结果。 例如,在“事件”页面上,我单击第2行的超链接,然后将我带到具有该特定事件的结果的“结果”页面。 任何帮助将不胜感激,因为我是PHP的新手。 如果需要任何其他详细信息,请随时询问。 谢谢。 编辑:对不起,我将向您展示“事件”表单到目前为止的样子: <?php mysql_connect('localhost','root',''); mysql_select_db('clubresults') or die( "Unable to select database"); $sql = "SELECT *, DATE_FORMAT(EventDate, '%d/%m/%y') as newdate FROM Events"; $result = mysql_query ($sql); ?> <table border = 1> <tr> <th>Event ID</th> th>Event Name</th> <th>Event Date</th> <th>Location</th> </tr> <?php while ($row = mysql_fetch_array($result)) { echo "</td><td>" .
  • Unable to edit db entries using EFCore, EntityState.Modified: “Database operation expected to affect 1 row(s) but actually affected 0 row(s).”
    I'm using Identity Core 1.0 with ASP.NET MVC Core 1.0 and Entity Framework Core 1.0 to create a simple user registration system with this article as a starting point, and I am trying to add user roles. I can add user roles, but I'm unable to edit them. Here is the Edit action in the RolesController: [HttpPost] [ValidateAntiForgeryToken] public IActionResult Edit(IdentityRole role) { try { _db.Roles.Attach(role); _db.Entry(role).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _db.SaveChanges(); return RedirectToAction("Index"); } catch (Exception ex) { Console.WriteLine(ex); return
  • 解析错误:语法错误,我的PHP代码中文件意外结束(Parse error: Syntax error, unexpected end of file in my PHP code)
    问题 我收到一个错误: Parse error: syntax error, unexpected end of file in the line 使用此代码: <html> <?php function login() { // Login function code } if (login()) {?> <h2>Welcome Administrator</h2> <a href=\"upload.php\">Upload Files</a> <br /> <a href=\"points.php\">Edit Points Tally</a> <?php} else { echo "Incorrect login details. Please login"; } ?> Some more HTML code </html> 有什么问题? 回答1 您应该避免这种情况(在代码末尾): {?> 还有这个: <?php} 您不应该将方括号直接放在php标签的开/关附近,而应使用空格隔开: { ?> <?php { 还避免<? 并使用<?php 回答2 我有同样的错误,但是我通过修改php.ini文件进行了修复。 找到您的php.ini文件,请参见Dude,我的php.ini在哪里? 然后使用您最喜欢的编辑器将其打开。 查找short_open_tag属性,并应用以下更改:
  • Unable to generate Jooq Classes from H2 using JPADatabase
    Im currently trying to generate jooq classes from jpa entities instead of using an existing db. Following this page and using jooq version 3.9.1, my current pom's plugin section looks like <profile> <id>jooq-jpa</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.jooq</groupId> <artifactId>jooq-codegen-maven</artifactId> <version>${jooq.version}</version> <dependencies> <dependency> <groupId>org.jooq</groupId>
  • Combining Flask-restless, Flask-security and regular Python requests
    My goal is to provide a REST API to my web application. Using: Python 2.7.5 Flask==0.10.1 Flask-Restless==0.13.1 Flask-Security==1.7.3 I need to secure access to my data for both web and REST access. However, I am unable to get any regular python request succeeding when trying to connect to secured API. The following outputs are obtained using the fully-functional module provided at the end of this question. I manage to get a correct answer when using >>> import requests >>> r=requests.get('') >>> print 'status:'
  • 如何将mysql转换为mysqli? [复制](How to convert mysql to mysqli? [duplicate])
    问题 这个问题在这里已经有了答案: 如何将mysql更改为mysqli? (12 个回答) 17 天前关闭。 我厌倦了将我的 mysql 转换为 mysqli 但似乎收到了很多错误和警告我没有问题连接到数据库但其余的代码似乎错了我做错了什么? sql: <?php mysql_connect("localhost", "root", ""); mysql_select_db("searchengine"); $sql = mysql_query(sprintf( "SELECT * FROM searchengine WHERE pagecontent LIKE '%s' LIMIT 0,%d", '%'. mysql_real_escape_string($_GET['term']) .'%', $_GET['results'])); while($ser = mysql_fetch_array($sql)) { echo "<h2><a href='$ser[pageurl]'>$ser[pageurl]</a></h2>"; } // don't forget to close connection mysql_close(); ?> mysqli <?php mysqli_connect("localhost","root","","searchengine") or
  • Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery`1[]' using linq lambda expression
    i'm new to mvc and trying to get idea of what i'm doing wrong i create a Dbcontaxt class public class DataBaseContext : DbContext { public DataBaseContext() : base("DefaultConnection") { } public DbSet<Membership> Membership { get; set; } public DbSet<OAuthMembership> OAuthMembership { get; set; } public DbSet<Role> Roles { get; set; } public DbSet<UserProfile> UserProfiles { get; set; } public DbSet<Category> Categorys { get; set; } public DbSet<SubCategory> SubCategorys { get; set; } public DbSet<Product> Products { get; set; } public DbSet<Color> Colors { get; set; } public DbSet<Size>
  • 将 mysql 转换为 mysqli?(Convert mysql to mysqli?)
    问题 我正在尝试将我的代码更改为mysqli ,我听说不推荐使用mysql并且我无法将我的代码更改为mysqli 。 我设法连接到我的数据库,但其余的代码似乎不起作用,我尝试将所有mysql更改为mysqli但它没有用。 我该怎么做才能使代码工作相同但在mysqli ? 有人可以重写它,以便我可以看到差异。 没看到什么好的教程。 <?php $db = new mysqli('localhost','root', '', 'searchengine'); if($db->connect_errno) { die('sorry we are having some problbems'); } $sql = mysql_query(sprintf( "SELECT * FROM searchengine WHERE pagecontent LIKE '%s' LIMIT 0,%d", '%'. mysql_real_escape_string($_GET['term']) .'%', mysql_real_escape_string($_GET['results'])) ); while($ser = mysql_fetch_array($sql)) { echo "<h2><a href='$ser[pageurl]'>$ser[pageurl]</a></h2>"; }
  • Unable to convert data frame to h2o object
    I am running the h2o package in Rstudio Version 0.99.447. I run version 10.9.5 OSX. I would like to set up a local cluster within R, following the steps of this tutorial: http://blenditbayes.blogspot.co.uk/2014/07/things-to-try-after-user-part-1-deep.html The first step does not seem to be a problem. What does seem to be a problem is converting my data frame to a proper h2o object. library(mlbench) dat = BreastCancer[,-1] #reading in data set from mlbench package library(h2o) localH2O <- h2o.init(ip = "localhost", port = 54321, startH2O = TRUE) #sets up the cluster dat_h2o <- as.h2o(localH2O
  • H2 Database not found error: 90146. H2 database is not created on start
    Just created a simple spring-boot project from the spring initializer. I went to add a local h2 db for testing and am unable to login. Seems that it cannot create the test db when starting up but cannot figure out why this may be the case. spring: h2: console: enabled: true path: /h2 datasource: url: jdbc:h2:mem:testdb; username: sa password: driver-class-name: org.h2.Driver platform: h2 jpa: show-sql: true hibernate: ddl-auto: create properties: hibernate: dialect=org: hibernate: dialect: H2Dialect: org.hibernate.dialect.H2Dialect Database "mem:testdb" not found, and IFEXISTS=true, so we cant
  • 在ASP.NET MVC 4中填充和选择下拉列表值(Populating and Selecting a Drop Down List Value in ASP.NET MVC 4)
    问题 ASP.NET MVC中的下拉列表使我感到困惑。 我有一个模型课。 该模型类具有一个名为SelectedValue的字符串。 此字符串表示先前选择的值。 我有一些从数据库中提取的项目。 集合的每个项目都有一个ID和一个Name值。 我的问题是,我不知道将这些信息输入UI的推荐方法是什么。 我不确定是否应该使用ViewBag或Model。 一旦有了值,我什至不知道填充UI的最佳方法是什么。 我见过HTML帮助者和使用RAZOR语法的人。 我很困惑人们推荐什么? 谢谢 回答1 这就是我的做法,可以说您有2个模型Team and Player : Player.cs public class Player { [HiddenInput(DisplayValue = false)] [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } [Required] [ForeignKey("Team")] [Display(Name = "Team")] public int TeamId { get; set; } [Display(Name = "First name")] public string FirstName { get; set; } [Display
  • Unable To populate view or view model Updaed
    Hi I am following up on this question here and working through a proof of concept for a SPA using our Company database data from a series of examples / articles Using Web API 2 with Entity Framework 6 Unfortunately, when I run the project I get this return This feels like a failure to retrieve the data from the SQL Database (SQL Server 2008R2). However I am getting no error message, which I though I would, I know the data view is there as I have checked in SQL Management studio and in Server Explorer of Visual Studio 2017. I am guessing though it could also be an error mapping my Data transfer
  • H2DB和Java,大约>两个小时的差异(H2DB and Java, an approximate> two hour discrepancy)
    问题 我正在开发一个比赛计时系统,在某些情况下,我需要从H2DB中检索一个时间对象。 像其bretheren(或sisteren)一样,time数据类型是相对于1970年1月1日的,并且以SQL形式以“ hh:mm:ss”格式表示,日期默认情况下设置为1970年1月1日。 默认情况下,它映射到“ java.sql.Time”对象。 作为值得信赖的Padawan,我将以下代码编码为显示目的,将小时数与分钟数分开。 if(race.getCutOffTime()!=null){ long cutOffHour=(race.getCutOffTime().getTime())/(3600000); int cutOffMinute=(int)(race.getCutOffTime().getTime()%(60*60*1000)); System.out.println(cutOffHour+":"+cutOffMinute); } 但是,Java的时间处理方式会产生臭味,因为这些函数输出意外的值,例如,我的数据库中的以下语句给出的输出为3:30。 INSERT INTO MagEye.Races(RaceName, EventID,CutOffTime) VALUES ('TEST', SELECT EventID FROM MagEye.Events WHERE EventName=
  • Tomcat6 can't connect to MySql (The driver has not received any packets from the server)
    i'm running an Apache Tomcat 6.0.20 / MySQL 5.1.37-lubuntu / sun-java6-jdk /sun-java6-jre / sun-java6-bin on my local machine using Ubuntu 9.10 as OS. I'm trying to get a simple DB-query example running for 2 days now, but i still get this Exception: org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not
  • H2DB and Java, an approximate> two hour discrepancy
    I am developing a race timing system, and for several instances, I need to retrieve a time object from H2DB. Like its bretheren (or sisteren), the time data type is relative to 1st January 1970 and is expressed in SQL in the 'hh:mm:ss' format, with the date being by set by default to 01-01-1970. It is by default mapped to the a 'java.sql.Time' object. Being a trusting padawan, I coded the following to separate hours from minutes for display purposes. if(race.getCutOffTime()!=null){ long cutOffHour=(race.getCutOffTime().getTime())/(3600000); int cutOffMinute=(int)(race.getCutOffTime().getTime()
  • 无法连接php和html文件(Unable to connect php and html file)
    问题 我添加了动作值注册文件 <body> <div id="registration"> <h2><b><i>Electronic Montessori Learning</i><b></h2> <form id="RegisterUserForm" action="connect.php" method="post"> <fieldset> <p> <label for="name">Name</label> <input id="name" name="name" type="text" class="text" value="" /> </p> <p> <label for="password">Password</label> <input id="password" name="password" class="text" type="password" /> </p> <p> <button id="registerNew" name="registerNew" type="submit">Register</button> </p> </fieldset> </form> </div> <body> 我没有发布所有的 registration.html 代码,因为它工作正常 连接.php <?php $db=mysql_connect("localhost",
  • Php/Mysql login authentication
    I am unable to authenticate using Php/mysql, using the following method. I used a form in order to login. Please check the following and help me out? form.php <html> <body> <h2>Authentication</h2> <form action="login.php" method="post"> <label>Userid :</label> <input type="text" id="userid" name="userid" > <label>Password :</label> <input type="password" id="password" name="password"> <input name="submit" type="submit" value=" Login "> <span><?php echo $error; ?></span> </form> </body> </html> login.php <?php $message=""; if(count($_POST)>0) { mysql_connect("localhost", "root", "kami123")or