找不到java.sql.sqlexception列 [英] java.sql.sqlexception column not found

查看:411
本文介绍了找不到java.sql.sqlexception列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从事务表的tr_id(主键)中找到最大编号.
这是表格及其布局.

I am trying to find max no from tr_id (primary key) in transaction table.
Here is the table and it's layout.



这是我的线.


Here is my cord.

             try {
                ResultSet rs = db.getData("SELECT MAX(tr_id) FROM transaction");
                ResultSetMetaData meta = rs.getMetaData();
                for (int index = 1; index <= meta.getColumnCount(); index++) {
                    System.out.println("Column " + index + " is named " +    meta.getColumnName(index));
                }
                if (rs.first()) {
                    int tr_id = rs.getInt("tr_id");
               }


我正在使用JDBC连接.当我运行此电源线时,出现此错误.


I'm using JDBC connection. When I'm running this cord I'm getting this error.

        Column 1 is named MAX(tr_id)
        java.sql.SQLException: Column 'tr_id' not found.
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
    at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:955)
    at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:2570)
    at Controler.InvoiceFinalising.saveInvoice(InvoiceFinalising.java:57)
  etc..


事情是当我搜索"tr_id"列名称转到Max(tr_id)


The thing is when I'm searching out as "tr_id" column name goes to Max(tr_id)

推荐答案

这是因为SQL查询中的列名是max(tr_id).您可以将其写为

This is because the column name in your sql query is max(tr_id). You can write it as

ResultSet rs = db.getData("SELECT MAX(tr_id) as tr_id FROM transaction");

现在您将能够获得它.

这篇关于找不到java.sql.sqlexception列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆