亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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個贊

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

這么說吧。BigInteger這個類可以使用固定的方法來將BigInteger類型轉換為Long類型,而不是直接通過強轉的方式。

查看完整回答
反對 回復 2017-12-13
  • 2 回答
  • 0 關注
  • 2236 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號