鱼C论坛

 找回密码
 立即注册
查看: 569|回复: 7

[已解决]请问一下这个问题要怎么改呀?

[复制链接]
发表于 2023-7-11 01:13:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
Exception:Cannot determine value type from string '通识教育课程'

好像应该是要改数据库的类型,但是我改不来,有没有大佬能教一下,谢谢。


  1. <%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%>
  2. <%@ page errorPage="error.jsp"%>

  3. <html>
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>培养方案</title>
  8.     <style>
  9.         .center
  10.         {
  11.             text-align:center;
  12.             display: block;
  13.             margin: auto;
  14.         }
  15.         td
  16.         {
  17.             text-align: center;
  18.         }
  19.         table {

  20.             margin: 0 auto;

  21.             text-align: center;

  22.         }
  23.     </style>
  24. </head>
  25. <body>
  26. <img src="16.jpeg" height="100" class="center" >
  27. <div style="text-align:center;"><a href="https://cas.whu.edu.cn/" target="_blank"  >武汉大学信息门户</a></div>
  28. <h1 style="text-align:center;">武汉大学特色软件试验班培养方案</h1>
  29. <table border="1" width="700" height="50" id="mytable1">
  30.     <thead>
  31.     <tr>
  32.         <th>课程类别</th>
  33.         <th>课程名称</th>
  34.         <th>授课教师</th>
  35.         <th>课程学分</th>
  36.         <th>课程绩点</th>
  37.         <th>课本图片</th>
  38.     </tr>
  39.     </thead>
  40.     <tbody>
  41.     <button onclick="table1()">点击显示/隐藏表格(第一学期)</button>
  42.     <tr>
  43.         <td colspan="6" style="background-color:blanchedalmond;" height="50" style="text-align:center;" >第一学期</td>
  44.     </tr>

  45.     <%
  46.         try {
  47.             Class.forName("com.mysql.jdbc.Driver");
  48.             Connection con = DriverManager.getConnection(
  49.                     "jdbc:mysql://localhost:3306/book?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC", "root",
  50.                     "ming20040521");
  51.             //使用Statement对象
  52.             Statement stmt = con.createStatement();
  53.             ResultSet rs = stmt.executeQuery("select * from sheet1 ");

  54.             while (rs.next()) {
  55.                 int sno = rs.getInt(1);
  56.                 out.println("<tr><td>" + rs.getString(1) + "</td><td>" +rs.getString(2) + "</td><td>"
  57.                         + rs.getString(3) + "</td><td>" + rs.getString(4)+"</td><td>"+ rs.getString(5) + "</td><td>"+
  58.                         rs.getString(6) + "</td><td>"+ "<td></tr>");

  59.             }
  60.             rs.close();
  61.             stmt.close();
  62.             con.close();
  63.         } catch (Exception e) {
  64.             out.println("Exception:" + e.getMessage());
  65.         }
  66.     %>

  67. </table>
  68. <table border="1" width="700" height="50" id="mytable2">
  69.     <thead>
  70.     <tr>
  71.         <th>课程类别</th>
  72.         <th>课程名称</th>
  73.         <th>授课教师</th>
  74.         <th>课程学分</th>
  75.         <th>课程绩点</th>
  76.         <th>课本图片</th>
  77.     </tr>
  78.     </thead>
  79.     <tbody>
  80.     <button onclick="table2()">点击显示/隐藏表格(第二学期)</button>
  81.     <tr>
  82.         <td colspan="6" style="background-color:blanchedalmond;" height="50" style="text-align:center;" >第二学期</td>
  83.     </tr>

  84. <script>
  85.     function table1()
  86.     {
  87.         var table = document.getElementById("mytable1");
  88.         if (table.style.display === "none")
  89.         {
  90.             table.style.display = "table";
  91.         }
  92.         else
  93.         {
  94.             table.style.display = "none";
  95.         }
  96.     }

  97. </script>
  98.     <script>
  99.         function table2()
  100.         {
  101.             var table = document.getElementById("mytable2");
  102.             if (table.style.display === "none")
  103.             {
  104.                 table.style.display = "table";
  105.             }
  106.             else
  107.             {
  108.                 table.style.display = "none";
  109.             }
  110.         }
  111.     </script>
  112. </body>
  113. </html>
复制代码
最佳答案
2023-7-11 16:10:44
这个错误信息表明在数据库查询结果中,有一个字符串'通识教育课程'无法确定其对应的值类型。从代码来看,这个问题可能出现在以下这行代码:
  1. out.println("<tr><td>" + rs.getString(1) + "</td><td>" +rs.getString(2) + "</td><td>"
  2.                         + rs.getString(3) + "</td><td>" + rs.getString(4)+"</td><td>"+ rs.getString(5) + "</td><td>"+
  3.                         rs.getString(6) + "</td><td>"+ "<td></tr>");
复制代码

在这里,你将数据库查询结果的各个字段都视为字符串使用了rs.getString()方法,但是如果数据库中的字段实际上是其他数据类型(如整数、浮点数等),就会导致类型转换错误。

要解决这个问题,你需要确定数据库中每个字段的实际数据类型,并使用相应的ResultSet方法进行获取。例如,如果某个字段是整数类型,可以使用rs.getInt()方法;如果是浮点数类型,可以使用rs.getFloat()方法。

你可以根据数据库中每个字段的实际类型进行相应的更改。这样就可以正确地确定每个字段的值类型,避免类型转换错误。
QQ截图20230711011236.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-7-11 01:26:23 | 显示全部楼层

回帖奖励 +5 鱼币

这个前端代码跟你的数据库没有关系吧?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-7-11 01:31:21 | 显示全部楼层
isdkz 发表于 2023-7-11 01:26
这个前端代码跟你的数据库没有关系吧?

应该是。。所以我应该怎么改数据库的东西,我把数据库贴在后面了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-7-11 11:30:23 | 显示全部楼层

回帖奖励 +5 鱼币

不懂,去问问gpt-> c.binjie.fun
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-7-11 11:30:52 | 显示全部楼层

回帖奖励 +5 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-7-11 12:10:50 | 显示全部楼层

回帖奖励 +5 鱼币

谢谢大佬的鱼币
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-7-11 13:49:01 From FishC Mobile | 显示全部楼层
Heng_Xin 发表于 2023-7-11 12:10
谢谢大佬的鱼币

。。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-7-11 16:10:44 | 显示全部楼层    本楼为最佳答案   
这个错误信息表明在数据库查询结果中,有一个字符串'通识教育课程'无法确定其对应的值类型。从代码来看,这个问题可能出现在以下这行代码:
  1. out.println("<tr><td>" + rs.getString(1) + "</td><td>" +rs.getString(2) + "</td><td>"
  2.                         + rs.getString(3) + "</td><td>" + rs.getString(4)+"</td><td>"+ rs.getString(5) + "</td><td>"+
  3.                         rs.getString(6) + "</td><td>"+ "<td></tr>");
复制代码

在这里,你将数据库查询结果的各个字段都视为字符串使用了rs.getString()方法,但是如果数据库中的字段实际上是其他数据类型(如整数、浮点数等),就会导致类型转换错误。

要解决这个问题,你需要确定数据库中每个字段的实际数据类型,并使用相应的ResultSet方法进行获取。例如,如果某个字段是整数类型,可以使用rs.getInt()方法;如果是浮点数类型,可以使用rs.getFloat()方法。

你可以根据数据库中每个字段的实际类型进行相应的更改。这样就可以正确地确定每个字段的值类型,避免类型转换错误。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-3 00:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表