繁体   English   中英

打印ASM代码以生成给定的类

[英]Printing the ASM code to generate the given class

我正在使用eclipse执行Java程序,以实现与MySQL的简单JDBC连接,其代码如下:

package samm;

import java.sql.*;

public class Sd {

    public static void main(String args[]) {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/sam", "root", "1234");

            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("select * from sam1");
            while (rs.next()) {
                System.out.println(rs.getInt(1) + "  " + rs.getString(2) + " " + rs.getString(3));
            }
            con.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }

}

我无法执行并无法获得所需的结果,但是,我收到一条错误消息,如下所示:“打印ASM代码以生成给定的类。用法:ASMifier [-debug]”

这行可能会引起问题:

System.out.println(rs.getInt(1) + "  " + rs.getString(2) + " " + rs.getString(3));

为什么这样,因为在您定义查询中的属性名称时使用了这种方式,所以它不是:

select * from sam1

您的查询应如下所示:

select attribute1, attribute2, attribute3 from sam1

第二种解决方案不是定义属性的索引,而是可以直接使用查询,但必须进行以下更改:

rs.getInt(1)

对此:

rs.getInt("name_of_the_attribute");// for example rs.getInt("id")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM