什么是“java.lang.NullPointerException”错误解决方案

时间:2014-08-06 15:34:48

标签: java mysql jsf

我遇到了一个错误。我的错误= { java.lang.NullPointerException }。我的错误解决方案是什么?我经常遇到这个错误。我想知道这个错误的原因是tomcat吗?谢谢。

enter image description here

其他İmages:

enter image description here

我的java classes1 [connDB.java]:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import javax.faces.bean.ManagedBean;

@ManagedBean

public class connDB {
public static String baglanti = null;
public static int baglantihatasi = 0;
public static String hataack = "";
public static java.sql.ResultSet veriler = null;
public static Statement sorgu = null;
public static Connection sorgula = null;


public static Statement  connect() {
    try {
                                                                                           sorgu=MyAcDb("obsKA","xx","xx","3306","obsDB");                 
        System.out.println("BAGLANDI");
    } catch (Exception ex) {          
        System.out.println("BAGLANTI HATASI");
    }
    return sorgu;
}

public static Statement MyAcDb(String kul, String sif, String ip,String port,String database) throws ClassNotFoundException {
    baglantihatasi = 0;
    Statement sorgulama= null;
    try{
               Class.forName("com.mysql.jdbc.Driver");
               Properties baglanInfo = new Properties();
               baglanInfo.put("characterEncoding", "latin5");
               baglanInfo.put("user", kul);
               baglanInfo.put("password", sif);
               baglanti = "jdbc:mysql://" + ip+":"+port + "/"+database;
               sorgula = DriverManager.getConnection(baglanti, baglanInfo);
               sorgulama =  (Statement) sorgula.createStatement();

        }catch(SQLException hata){

        }
        return sorgulama;
    }
  }

我的java classes2 [listDB.java]:

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.faces.bean.ManagedBean;

@ManagedBean
public class listDB {
private Statement sorgu=null;
boolean sonuc;
private int ogrenciID;
private String ogrenciAD;
private String ogrenciSOYAD;
private String ogrenciNO;
private String ogrenciFAKULTE;
private String ogrenciBOLUM;
private String ogrenciMAIL;

public int getOgrenciID() {return ogrenciID;}
public void setOgrenciID(int ogrenciID) {this.ogrenciID = ogrenciID;}

public String getOgrenciAD() {return ogrenciAD;}
public void setOgrenciAD(String ogrenciAD) {this.ogrenciAD = ogrenciAD;}

public String getOgrenciSOYAD() {return ogrenciSOYAD;}
public void setOgrenciSOYAD(String ogrenciSOYAD) {this.ogrenciSOYAD = ogrenciSOYAD;}

public String getOgrenciNO() {return ogrenciNO;}
public void setOgrenciNO(String ogrenciNO) {this.ogrenciNO = ogrenciNO;}

public String getOgrenciFAKULTE() {return ogrenciFAKULTE;}
public void setOgrenciFAKULTE(String ogrenciFAKULTE) {this.ogrenciFAKULTE = ogrenciFAKULTE;}

public String getOgrenciBOLUM() {return ogrenciBOLUM;}
public void setOgrenciBOLUM(String ogrenciBOLUM) {this.ogrenciBOLUM = ogrenciBOLUM;}

public String getOgrenciMAIL() {return ogrenciMAIL;}
public void setOgrenciMAIL(String ogrenciMAIL) {this.ogrenciMAIL = ogrenciMAIL;}



public ArrayList listele() throws SQLException{

        ArrayList list = new ArrayList();

        sorgu = connDB.connect();           
        String sqltext= "SELECT * FROM ogrenci";
        ResultSet veriler = sorgu.executeQuery(sqltext);

        while (veriler.next()) {
            listDB lst = new listDB();
            lst.setOgrenciID(veriler.getInt("ogrencıID"));
            lst.setOgrenciAD(veriler.getString("ogrenciAD"));
            lst.setOgrenciSOYAD(veriler.getString("ogrenciSOYAD"));
            lst.setOgrenciNO(veriler.getString("ogrenciNO"));
            lst.setOgrenciFAKULTE(veriler.getString("ogrenciFAKULTE"));
            lst.setOgrenciBOLUM(veriler.getString("ogrenciBOLUM"));
            lst.setOgrenciMAIL(veriler.getString("ogrenciMAIL"));
            list.add(lst);
        }      
        return list;          
    } 
 }

0 个答案:

没有答案