不寐人 2021-12-12 15:24 采纳率: 42.9%
浏览 25
已结题

关于idea的web项目和mysql的连接问题

这行代码开始警告没有配置mysql方言,
但我配置了全局方言后又报错说无法解析表,
除此之外所有的表和列都有报错,
明明数据库里面有这些表,
请问如何解决?

img

img

package lib.Dao;

import java.sql.*;

/**
 * Created by ttop5 on 16-4-18.
 */
public class StudentDAO {
//    public String getNotes() throws SQLException {
//        Statement stmt = null;
//        Dbutil dbutil = new Dbutil();
//        Connection con = null;
//        ResultSet rs = null;
//        String str = "<table class=\"table table-bordered\" id=\"outside\">" +
//                "<tr><th>标题</th><th>时间</th><th>公告内容</th></tr>";
//        try{
//            con = dbutil.getCon();
//            stmt = con.createStatement();
//            String sql = "select title, start_time, description from notes" + ";";
//            rs = stmt.executeQuery(sql);
//            while(rs.next()) {
//                str = str + "<tr>" + "<td>" + rs.getString("title") + "</td>" + "<td>" + rs.getDate("start_time") + "</td>" + "<td>" + rs.getString("description") + "</td>" + "</tr>";
//            }
//            return str + "</table>";
//        }catch (Exception e) {
//            e.printStackTrace();
//        }
//        return str;
//    }

    public String getNotes() throws SQLException{
        Statement stmt = null;
        Dbutil dbutil = new Dbutil();
        Connection con = null;
        ResultSet rs = null;
        String str = "<table class=\"table table-bordered\" id=\"outside\">" +
                "<tr><th>标题</th><th>开始时间</th><th>结束时间</th><th>公告内容</th></tr>";
        try{
            con = dbutil.getCon();
            stmt = con.createStatement();
            String sql = "select * from notes" + ";";
            rs = stmt.executeQuery(sql);
            while(rs.next()) {
                str = str + "<tr>" + "<td>" + rs.getString("title") + "</td>" + "<td>" + rs.getString("start_time") + "</td>" + "<td>" + rs.getString("stop_time") + "</td>" + "<td>" + rs.getString("description") + "</td>" + "</tr>";
            }
            return str + "</table>";
        }catch (Exception e) {
            e.printStackTrace();
        }
        return str;
    }

    public String getScore(String email) throws SQLException{
        Statement stmt = null;
        Dbutil dbutil = new Dbutil();
        Connection con = null;
        ResultSet rs = null;
        String str = "<table class=\"table table-bordered\" id=\"outside\">" +
                "<tr><th>课程号</th><th>课程名</th><th>学分</th><th>平时成绩</th><th>期末成绩</th><th>最终成绩</th></tr>";
        try{
            con = dbutil.getCon();
            stmt = con.createStatement();
            String sql = "select cource_id, cource_name, credit, pingshi_score, qimo_score, final_score from score, user, cource where student=user_id and cource=cource_id AND email='" + email + "';";
            rs = stmt.executeQuery(sql);
            while(rs.next()) {
                str = str + "<tr>" + "<td>" + rs.getInt("cource_id") + "</td>" + "<td>" + rs.getString("cource_name") + "</td>" + "<td>" + rs.getString("credit") + "</td>" + "<td>" + rs.getString("pingshi_score") + "</td>" + "<td>" + rs.getString("qimo_score") + "</td>" + "<td>" + rs.getString("final_score") + "</td>" + "</tr>";
            }
            return str + "</table>";
        }catch (Exception e) {
            e.printStackTrace();
        }
        return str;
    }

    public String getScource(String email) throws SQLException{
        Statement stmt = null;
        Dbutil dbutil = new Dbutil();
        Connection con = null;
        ResultSet rs = null;
        String str = "<table class=\"table table-bordered\" id=\"outside\">" +
                "<tr><th>课程号</th><th>课程名称</th><th>学分</th><th>上课时间</th><th>上课地点</th></tr>";
        try{
            con = dbutil.getCon();
            stmt = con.createStatement();
            String sql = "select cource_id, cource_name, credit, schooltime, location from score, user, cource, classroom where student=user_id and cource=cource_id and classroom=classroom_id AND email='" + email + "';";
            rs = stmt.executeQuery(sql);
            while(rs.next()) {
                str = str + "<tr>" + "<td>" + rs.getInt("cource_id") + "</td>" + "<td>" + rs.getString("cource_name") + "</td>" + "<td>" + rs.getString("credit") + "</td>" + "<td>" + rs.getString("schooltime") + "</td>" + "<td>" + rs.getString("location") + "</td>" + "</tr>";
            }
            return str + "</table>";
        }catch (Exception e) {
            e.printStackTrace();
        }
        return str;
    }

    public String getUser(String email) throws SQLException{
        Statement stmt = null;
        Dbutil dbutil = new Dbutil();
        Connection con = null;
        ResultSet rs = null;
        String str = "<table class=\"table table-bordered\" id=\"outside\">" +
                "<tr><th>学号</th><th>姓名</th><th>性别</th><th>年级</th><th>学院</th><th>专业</th><th>班级</th><th>QQ</th><th>电话</th><th>邮箱</th><th>地址</th><th>角色</th></tr>";
        try{
            con = dbutil.getCon();
            stmt = con.createStatement();
            String sql = "select * from user WHERE email='" + email + "';";
            rs = stmt.executeQuery(sql);
            while(rs.next()) {
                str = str + "<tr>" + "<td>" + rs.getString("school_num") + "</td>" + "<td>" + rs.getString("name") + "</td>" + "<td>" + rs.getString("sex") + "</td>" +"<td>" + rs.getString("grade") + "</td>" + "<td>" + rs.getString("school") + "</td>" + "<td>" + rs.getString("major") + "</td>" + "<td>" + rs.getString("class") + "</td>" + "<td>" + rs.getString("qq") + "</td>" + "<td>" + rs.getString("phone") + "</td>" + "<td>" + rs.getString("email") + "</td>" + "<td>" + rs.getString("adress") + "</td>" + "<td>" + rs.getString("role") + "</td>" +
                        "<td><button type=\"button\" class=\"btn btn-success\">编辑</button></td>" + "</tr>";
            }
            return str + "</table>";
        }catch (Exception e) {
            e.printStackTrace();
        }
        return str;
    }
}


  • 写回答

1条回答 默认 最新

  • 未聞花名丶 2021-12-12 16:02
    关注

    这个无所谓吧,编译不报错就ok

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 12月12日
  • 创建了问题 12月12日

悬赏问题

  • ¥15 暴雪战网api相关问题
  • ¥15 而使用UE5引擎的 工具选项里 打开c++ visual studio 就会有部分显示加载失败 如图 加载失败的这张图 请问是什么原因
  • ¥15 mysql 对多个字段模糊查询,返回第一个匹配的字段
  • ¥15 the testing results of the whole dataset is empty
  • ¥15 can问题,往哥解决
  • ¥15 FFmpeg 成功推流到 Nginx RTMP 服务器但无法用 ffplay 或 VLC 播放
  • ¥15 请修改以下C语言代码使其能正确输出最短路径
  • ¥20 抖音商城拉码器安卓报错求解决办法或者有新的拉码脚本也可以介绍一下
  • ¥15 MPLAB IDE V2.35 报错make[2]: *** [build/default/production/_ext/1472/MSSP_I2C.p1] Error 1
  • ¥15 在国外文献网站里点击view pdf 加载异常缓慢甚至加载不出来。