美文网首页
JSP连接MySQL数据库(坑!!!!!!!)

JSP连接MySQL数据库(坑!!!!!!!)

作者: HSHF | 来源:发表于2018-11-16 21:00 被阅读0次

    注意(死坑):

    确定自己电脑可以连接到数据库,并且没有异常(我是数据库有问题,没发现,一直改改代码。。。。。)

    数据库驱动导入lib文件夹内

    数据库名,表名没有错误,查询语句没有错误

    Class.forName("com.mysql.jdbc.Driver");

    Connection conn = null;

    String url = "jdbc:mysql://192.168.1.3:3306/stu";     //stu数据库名字

    try{

    conn = DriverManager.getConnection(url, "root", "123456");            //账号密码

    }catch(Exception e){            //异常提醒

    out.println("数据库连接失败");

    }

    String sql = "select dName from stu01";                //SQL语句

    Statement statement;

    try{

    statement = conn.createStatement();

    ResultSet rest = statement.executeQuery(sql);   //执行SQL语句

    }

    }catch(Exception e){

    out.print("数据库查询失败");            //异常提醒

    }

    %>

    相关文章

      网友评论

          本文标题:JSP连接MySQL数据库(坑!!!!!!!)

          本文链接:https://www.haomeiwen.com/subject/lwymfqtx.html