java.math.BigInteger cannot be cast to java.lang.Long始终报错

package Dao;


import java.sql.*;

public class sql {

 

    public static void main(String[] args) {


        Connection con;

        String driver = "com.mysql.jdbc.Driver";

        String url = "jdbc:mysql://localhost:3306/bus";

        String user = "root";

        String password = "123456";


        try {

            Class.forName(driver);

            System.out.println("1");

            con = DriverManager.getConnection(url,user,password);

            if(!con.isClosed())

                System.out.println("Succeeded connecting to the Database!");

            Statement statement = con.createStatement();

            String sql = "select * from user";

            ResultSet rs = statement.executeQuery(sql);

            System.out.println("-----------------");

            System.out.println("执行结果如下所示:");  

            System.out.println("-----------------");  

            System.out.println(" 学号" + "\t" + " 姓名");  

            System.out.println("-----------------");

            System.out.println("ok");

             

            String name = null;

            String id = null;

            while(rs.next()){

                name = rs.getString("name");

                id = rs.getString("password");

                name = new String(name.getBytes("ISO-8859-1"),"gb2312");

                System.out.println(id + "\t" + name);

            }

            rs.close();

            con.close();

        } catch(ClassNotFoundException e) {   

            System.out.println("Sorry,can`t find the Driver!");   

            e.printStackTrace();   

            } catch(SQLException e) {

            System.out.println("2");

            e.printStackTrace();  

            }catch (Exception e) {

            e.printStackTrace();

        }finally{

            System.out.println("数据库数据成功获取!!");

        }

    }

 

}


枫夜流萤
浏览 2119回答 2
2回答

古__月

这么说吧。BigInteger这个类可以使用固定的方法来将BigInteger类型转换为Long类型,而不是直接通过强转的方式。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java