请问这个问题解决?江湖救急

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

10回答
提问者 燚燚炎 2019-07-13 19:02:40

http://img1.sycdn.imooc.com//climg/5d29ba4100011cae19200913.jpg

可以运行了,谢谢老师

提问者 燚燚炎 2019-07-13 18:13:34

http://img1.sycdn.imooc.com//climg/5d29ad7f0001dffb19200913.jpg

http://img1.sycdn.imooc.com//climg/5d29ad8d0001395a04760233.jpg

输入的密码和账户是数据库里面的为啥会报错啊,麻烦老师看看谢谢

  • 问一下同学控制台有报错吗?建议同学查看一下。祝:学习愉快~
    2019-07-13 18:44:24
提问者 燚燚炎 2019-07-13 16:55:02

http://img1.sycdn.imooc.com//climg/5d299c1c0001e7ec12990760.jpg

http://img1.sycdn.imooc.com//climg/5d299c3700012e7403250055.jpg

老师我司导入的,我的mysql版本是5.7,架包是5.0.4

好帮手慕阿满 2019-07-13 16:41:31

同学你好,试验同学的代码,并没有什么问题。同学的报错是找不到JDBCUtils类,问一下同学是否有导入mysql的jar包以及c3p0的jar包,如:

http://img1.sycdn.imooc.com//climg/5d29991b000117d002790149.jpg

mysql的jar包版本是否和本地的mysql版本相同。建议同学查看一下。

祝:学习愉快~

提问者 燚燚炎 2019-07-13 16:23:32

老师你看到了,请你看看啊,谢谢,江湖救急

提问者 燚燚炎 2019-07-13 13:16:28

F:\Download\apache-tomcat-8.5.42\bin\catalina.bat run
[2019-07-13 01:14:14,771] Artifact PicShop:war exploded: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE:   "C:\Users\Administrator\.IntelliJIdea2018.1\system\tomcat\Tomcat_8_5_42_Shop"
Using CATALINA_HOME:   "F:\Download\apache-tomcat-8.5.42"
Using CATALINA_TMPDIR: "F:\Download\apache-tomcat-8.5.42\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk1.8.0_121"
Using CLASSPATH:       "F:\Download\apache-tomcat-8.5.42\bin\bootstrap.jar;F:\Download\apache-tomcat-8.5.42\bin\tomcat-juli.jar"
13-Jul-2019 13:14:15.794 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.42
13-Jul-2019 13:14:15.801 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jun 4 2019 20:29:04 UTC
13-Jul-2019 13:14:15.802 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.42.0
13-Jul-2019 13:14:15.802 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 10
13-Jul-2019 13:14:15.802 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            10.0
13-Jul-2019 13:14:15.802 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
13-Jul-2019 13:14:15.802 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             C:\Program Files\Java\jdk1.8.0_121\jre
13-Jul-2019 13:14:15.802 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_121-b13
13-Jul-2019 13:14:15.802 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
13-Jul-2019 13:14:15.802 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         C:\Users\Administrator\.IntelliJIdea2018.1\system\tomcat\Tomcat_8_5_42_Shop
13-Jul-2019 13:14:15.802 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         F:\Download\apache-tomcat-8.5.42
13-Jul-2019 13:14:15.803 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\Administrator\.IntelliJIdea2018.1\system\tomcat\Tomcat_8_5_42_Shop\conf\logging.properties
13-Jul-2019 13:14:15.803 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
13-Jul-2019 13:14:15.803 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
13-Jul-2019 13:14:15.803 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
13-Jul-2019 13:14:15.803 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
13-Jul-2019 13:14:15.804 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
13-Jul-2019 13:14:15.804 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
13-Jul-2019 13:14:15.804 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
13-Jul-2019 13:14:15.804 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
13-Jul-2019 13:14:15.804 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
13-Jul-2019 13:14:15.804 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\Administrator\.IntelliJIdea2018.1\system\tomcat\Tomcat_8_5_42_Shop
13-Jul-2019 13:14:15.804 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=F:\Download\apache-tomcat-8.5.42
13-Jul-2019 13:14:15.804 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=F:\Download\apache-tomcat-8.5.42\temp
13-Jul-2019 13:14:15.805 淇℃伅 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.21] using APR version [1.6.5].
13-Jul-2019 13:14:15.805 淇℃伅 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
13-Jul-2019 13:14:15.805 淇℃伅 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
13-Jul-2019 13:14:15.811 淇℃伅 [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1a  20 Nov 2018]
13-Jul-2019 13:14:15.968 淇℃伅 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
13-Jul-2019 13:14:15.986 淇℃伅 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
13-Jul-2019 13:14:16.021 淇℃伅 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
13-Jul-2019 13:14:16.024 淇℃伅 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
13-Jul-2019 13:14:16.025 淇℃伅 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 599 ms
13-Jul-2019 13:14:16.063 淇℃伅 [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
13-Jul-2019 13:14:16.064 淇℃伅 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.42
13-Jul-2019 13:14:16.095 淇℃伅 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
13-Jul-2019 13:14:16.109 淇℃伅 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
13-Jul-2019 13:14:16.112 淇℃伅 [main] org.apache.catalina.startup.Catalina.start Server startup in 86 ms
Connected to server
[2019-07-13 01:14:16,350] Artifact PicShop:war exploded: Artifact is being deployed, please wait...
13-Jul-2019 13:14:16.599 璀﹀憡 [RMI TCP Connection(3)-127.0.0.1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used.
[2019-07-13 01:14:16,794] Artifact PicShop:war exploded: Artifact is deployed successfully
[2019-07-13 01:14:16,794] Artifact PicShop:war exploded: Deploy took 444 milliseconds
13-Jul-2019 13:14:26.101 淇℃伅 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [F:\Download\apache-tomcat-8.5.42\webapps\manager]
13-Jul-2019 13:14:26.149 淇℃伅 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [F:\Download\apache-tomcat-8.5.42\webapps\manager] has finished in [47] ms
aaa    12

//谢谢老师,老师辛苦了,刚刚我查了资料和调试了还是不行,


提问者 燚燚炎 2019-07-13 13:16:08
package com.imooc.utils;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * JDBC的工具类
 *
 */
public class JDBCUtils {
   public static final ComboPooledDataSource dataSource = new ComboPooledDataSource();
   
   /**
    * 获得连接
    * @throws Exception 
    */

   public static Connection getConnection() throws Exception{
      return dataSource.getConnection();
   }
   
   /**
    * 获得连接池
    */
   public static DataSource getDataSource(){
      return dataSource;
   }
   
   /**
    * 释放资源
    */
   public static void release(ResultSet rs,Statement stmt,Connection conn){
      if(rs != null){
         try {
            rs.close();
         } catch (SQLException e) {
            e.printStackTrace();
         }
         rs = null;
      }
      if(stmt != null){
         try {
            stmt.close();
         } catch (SQLException e) {
            e.printStackTrace();
         }
         stmt = null;
      }
      if(conn != null){
         try {
            conn.close();
         } catch (SQLException e) {
            e.printStackTrace();
         }
         conn = null;
      }
   }
   
   public static void release(Statement stmt,Connection conn){
      if(stmt != null){
         try {
            stmt.close();
         } catch (SQLException e) {
            e.printStackTrace();
         }
         stmt = null;
      }
      if(conn != null){
         try {
            conn.close();
         } catch (SQLException e) {
            e.printStackTrace();
         }
         conn = null;
      }
   }
}

package com.imooc.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.imooc.dao.UserDao;
import com.imooc.domain.User;
import com.imooc.utils.JDBCUtils;

public class UserDaoImpl implements UserDao {

   @Override
   public User login(User user) {

      Connection conn = null;
      PreparedStatement pstmt = null;
      ResultSet rs = null;
      try{
         // 获得连接
         conn = JDBCUtils.getConnection();
         // 编写SQL
         String sql = "select * from user where username = ? and password = ?";
         // 预编译SQL
         pstmt = conn.prepareStatement( sql);
         // 设置参数
         pstmt.setString(1, user.getUsername());
         pstmt.setString(2, user.getPassword());
         // 执行
         rs = pstmt.executeQuery();
         if(rs.next()){
            User existUser = new User();
            existUser.setUid(rs.getInt("uid"));
            existUser.setUsername(rs.getString("username"));
            existUser.setPassword(rs.getString("password"));
            return existUser;
         }
      }catch(Exception e){
         e.printStackTrace();
      }finally{
         // 释放资源
         JDBCUtils.release(rs, pstmt, conn);
      }
      return null;
   }

}
提问者 燚燚炎 2019-07-12 19:53:37

http://img1.sycdn.imooc.com//climg/5d28742c0001065004170592.jpg

http://img1.sycdn.imooc.com//climg/5d28743b0001926213140701.jpg

http://img1.sycdn.imooc.com//climg/5d28744c0001fc6812150815.jpg

http://img1.sycdn.imooc.com//climg/5d28747800017c9b11190771.jpg

http://img1.sycdn.imooc.com//climg/5d2874a00001dd6111720810.jpg

http://img1.sycdn.imooc.com//climg/5d2874b300012dc613290447.jpg

麻烦老师看看,谢谢

  • 同学你好,建议同学将代码贴上来,贴在回答中,选择代码语言,不要截图哦,方便老师具体测试。另外建议同学将控制台的报错也贴一下。祝:学习愉快~
    2019-07-13 11:14:43
吃吃吃鱼的猫 2019-07-12 19:35:38

同学你好,建议同学贴出项目结构(特别是JDBCUtils类的目录结构),JDBCUtils类,UserDaoImpl类中的代码,方便老师为同学解答~

同学先贴出以上信息,老师先帮你看一下~

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

吃吃吃鱼的猫 2019-07-12 18:05:41

同学你好,根据报错提示可知,无法初始化JDBCUtils这个类。

可能是由于此类的变量或方法中,引用配置文件的数据但是没有成功。

同学检查一下配置文件是否读取正确。

http://img1.sycdn.imooc.com//climg/5d285a840001fb1811780309.jpg

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

  • 提问者 燚燚炎 #1
    还是不行啊。我把UserDaoImpl 和UserServiceImpl和UserServlet的源码帖进去还是不行,要不我把源码发给你你帮我跑一下吧,谢谢!
    2019-07-12 18:53:28
  • 兄弟,问题解决了吗,我的问题好像跟你一样
    2019-08-12 11:12:00
  • 同学具体遇到了什么问题呢?建议同学新开一个问答,描述一下自己的问题呢。祝学习愉快~
    2019-08-12 14:46:09
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师