为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

枫夜流萤 2017-12-13 15:32:04
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("数据库数据成功获取!!");        }    } }
查看完整描述

2 回答

已采纳
?
古__月

TA贡献44条经验 获得超22个赞

//img1.sycdn.imooc.com//5a30e35600017e7a04870210.jpg

这么说吧。BigInteger这个类可以使用固定的方法来将BigInteger类型转换为Long类型,而不是直接通过强转的方式。

查看完整回答
反对 回复 2017-12-13
  • 2 回答
  • 0 关注
  • 2116 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信