Allons. 2019-05-07 15:04 采纳率: 0%
浏览 353

小白使用JDBC遇到问题求大佬们解答

在IDEA上使用JDBC出现bug,求解答
报错如下:
图片说明

图片说明

代码如下:


package cn.tju.scs;
import java.sql.*;
public class JDBC {
    static final String jdbcDriver = "com.mysql.jdbc.Driver";
    static final String databaseUrl = "jdbc:mysaql://localhost:3306/testone";
    static final String user = "root";
    static final String passWord = "swy435998290";

    publtatic void main(String[] args) {
            Connection conn = null;
            Statement stmt = null;
            try{
                // 注册 JDBC 驱动
                Class.forName("com.mysql.jdbc.Driver");

                // 打开链接
                System.out.println("连接数据库...");
                conn = DriverManager.getConnection(databaseUrl,user,passWord);
                // 执行查询
                System.out.println(" 实例化Statement对象...");
                stmt = conn.createStatement();
                String sql;
                sql = "SELECT * FROM course";
                ResultSet rs = stmt.executeQuery(sql);

                // 展开结果集数据库
                while(rs.next()){
                    // 通过字段检索
                    int cid  = rs.getInt("cid");
                    String cName = rs.getString("cName");
                    // 输出数据
                    System.out.print("cid: " + cid);
                    System.out.print(", 站点名称: " +cName);
                    System.out.print("\n");
                }
                // 完成后关闭
                rs.close();
                stmt.close();
                conn.close();
            }catch(SQLException se){
                // 处理 JDBC 错误
                se.printStackTrace();
            }catch(Exception e){
                // 处理 Class.forName 错误
                e.printStackTrace();
            }finally{
                // 关闭资源
                try{
                    if(stmt!=null) stmt.close();
                }catch(SQLException se2){
                }// 什么都不做
                try{
                    if(conn!=null) conn.close();
                }catch(SQLException se){
                    se.printStackTrace();
                }
            }
            System.out.println("Goodbye!");
        }
    }ic s
  • 写回答

4条回答 默认 最新

  • qq_41126602 2019-05-07 15:10
    关注

    你这代码写错了:"jdbc:mysaql://localhost:3306/testone"; 改成 这个 你是一下 "jdbc:mysql://localhost:3306/testone";

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog