在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ eclipse報(bào)錯(cuò)

eclipse報(bào)錯(cuò)

eclipse報(bào)An error has occurred,See error log for more details. java.lang.NullPointerException,我在網(wǎng)上查了一推資料還是沒解決問題,各位大神有高見?下面是我的代碼:UserInfoDao.java

package com.main.dao;
//查詢用戶名,密碼。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class UserInfoDao {
    public void login(char username,char pass) {

         Connection con;
         //驅(qū)動(dòng)程序名
         String driver = "com.mysql.jdbc.Driver";
         //URL指向要訪問的數(shù)據(jù)庫名mydata
         String url = "jdbc:mysql://localhost:3306/peoplepower";
         //MySQL配置時(shí)的用戶名
         String user = "root";
         //MySQL配置時(shí)的密碼
         String password = "123459";
           //遍歷查詢結(jié)果集
                  try {
                      //加載驅(qū)動(dòng)程序
                      Class.forName(driver);
                      //1.getConnection()方法,連接MySQL數(shù)據(jù)庫?。?                      con = DriverManager.getConnection(url,user,password);
                      if(!con.isClosed())
                          System.out.println("Succeeded connecting to the Database!");
                      //2.創(chuàng)建statement類對(duì)象,用來執(zhí)行SQL語句??!
                      Statement statement = con.createStatement();
                      //要執(zhí)行的SQL語句
                      String sql="select * from userinfo where username='"+username+"and password='"+pass+"'";
                      //3.ResultSet類,用來存放獲取的結(jié)果集??!
                      ResultSet rs = statement.executeQuery(sql);
                      System.out.println("-----------------");
                      System.out.println("執(zhí)行結(jié)果如下所示:");  
                      System.out.println("-----------------");  
                      System.out.println("用戶名" + "\t" + "密碼");  
                      System.out.println("-----------------");  
                       
                      String us = null;
                      String psw = null;
                      while(rs.next()){
                          //獲取stuname這列數(shù)據(jù)
                          us = rs.getString("username");
                          //獲取stuid這列數(shù)據(jù)
                          psw = rs.getString("password");
          
                          //輸出結(jié)果
                          System.out.println(us + "\t" + psw);
                      }
                      rs.close();
                      con.close();
                  } catch(ClassNotFoundException e) {   
                      //數(shù)據(jù)庫驅(qū)動(dòng)類異常處理
                      System.out.println("Sorry,can`t find the Driver!");   
                      e.printStackTrace();   
                      } catch(SQLException e) {
                      //數(shù)據(jù)庫連接失敗異常處理
                      e.printStackTrace();  
                      }catch (Exception e) {
                      // TODO: handle exception
                      e.printStackTrace();
                  }finally{
                      System.out.println("數(shù)據(jù)庫數(shù)據(jù)成功獲?。?!");
                  }
    }
    
    public void main(String[] args) {
        UserInfoDao dao=new UserInfoDao();
        dao.login('1', '1');
    }
}

在tomcat上運(yùn)行后出現(xiàn)以下結(jié)果:

clipboard.png

回答
編輯回答
挽青絲

你知道web-inf目錄的作用嗎?只能有服務(wù)器來訪問,瀏覽器是無法訪問的,所以你直接訪問web-inf目錄下的東西就會(huì)報(bào)404

2017年3月15日 09:27
編輯回答
涼薄

沒寫注解,控制層沒寫注解,請(qǐng)求這個(gè)接口就會(huì)報(bào)404.
另外,Web-inf 目錄下的文件是不可以直接用過地址訪問的

2018年7月29日 23:01
編輯回答
下墜

這樣的問題需要提供詳細(xì)日志才能讓別人幫你看哪里出了問題,我建議你打個(gè)斷點(diǎn)進(jìn)去一步一步的排查比較好。

2018年2月10日 02:26