Results 1 to 4 of 4
  1. #1
    miko5054 is offline Member
    Join Date
    Mar 2010
    Posts
    50
    Rep Power
    0

    Default Jdbc null pointer exception

    im tring to wite a jdbc class but greeting a NULL pointer exception on this line

    resultSet = preparedStatement.executeQuery(sql);


    this is the complete code...
    Java Code:
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.Date;
    
    public class Select {
    //	java.util.Date today = new java.util.Date();
    //	java.sql.Date timeStamp = new java.sql.Date(today.getTime());
    	
    	
    	DataBean dataBean = null;
    	String localtransactionid ;
    	int eventsequenceid = 0;
    	Date  eventtimestamp=null;
    	String msgflowname = null;
    	String eventname = null;
    	String brokername = null;
    	String severity = null;
    	String businesstransactionid = null;
    	String url = "***********";
    	String username = "*****";
    	String password = "*****";
    	PreparedStatement preparedStatement = null;
        Statement st = null;
    	ResultSet resultSet = null;
    	Connection connection = null;
    
    	public Select() {
    		connection = getConnection();
    	}
    
    	private Connection getConnection() {
    		try {
    			if (connection == null || connection.isClosed()) {
    				Class.forName("oracle.jdbc.driver.OracleDriver");
    				connection = (DriverManager.getConnection(url, username,
    						password));
    			}
    		} catch (Exception e) {
    		}
    		return connection;
    
    	}
    
    	public DataBean selectFilters(String msgflowname, String eventname,
    		
    			String severity, String businesstransactionid,
    			String localtransactionid, Date  eventtimestamp, int eventsequenceid) {
    		StringBuilder builder = new StringBuilder();
    		builder.append("SELECT eventtimestamp,msgflowname,eventname,severity,localtransactionid,eventsequenceid,businesstransactionid");
    		builder.append(" FROM ESB_LOGGER ");
    		builder.append(" WHERE ");
    		if (localtransactionid != null) {
    			builder.append("localtransactionid=" + localtransactionid + ",");
    		}
    		if (eventsequenceid != 0) {
    			builder.append("eventsequenceid=" + eventsequenceid + ",");
    
    		}
    		if (eventtimestamp != null) {
    			builder.append("eventtimestamp=" + eventtimestamp + ",");
    		}
    		if (msgflowname != null) {
    			builder.append("msgflowname=" + msgflowname + ",");
    		}
    		if (eventname != null) {
    			builder.append("eventname=" + eventname + ",");
    		}
    		if (brokername != null) {
    			builder.append("brokername=" + eventname + ",");
    		}
    		if (severity != null) {
    			builder.append("severity=" + severity + ",");
    		}
    		if (businesstransactionid != null) {
    			builder.append("businesstransactionid==" + businesstransactionid + ",");
    		} else {
    			System.err.println("all the query is  null");
    		}
    		builder.append("ORDER BY "+eventtimestamp+ " DESC");
    		System.out.println(builder.toString());
    		String sql = builder.toString();
    		try {
    		resultSet = preparedStatement.executeQuery(sql);
    			while (resultSet.next()) {
    				localtransactionid = resultSet.getString("LOCALTRANSACTIONID");
    				String eventseqid = resultSet.getString("EVENTSEQUENCEID");
    				eventtimestamp = resultSet.getDate("EVENTTIMESTAMP");
    				eventname = resultSet.getString("EVENTNAME");
    				businesstransactionid = resultSet
    						.getString("BUSINESSTRANSACTIONID");
    					severity = resultSet.getString("SEVERITY");
    				eventsequenceid = Integer.parseInt(eventseqid);
    				dataBean = new DataBean(eventtimestamp, msgflowname, eventname,
    						severity, localtransactionid, eventsequenceid,
    						businesstransactionid);
    
    			}
    			preparedStatement.close();
    			resultSet.close();
    			connection.close();
    		} catch (SQLException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return dataBean;
    
    		}
    		
    }
    thanks miki
    Last edited by miko5054; 02-24-2011 at 10:41 AM.

  2. #2
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    450
    Rep Power
    6

    Default

    If possible post your error log. Then only find out exactly where the bug is.
    Mak
    (Living @ Virtual World)

  3. #3
    miko5054 is offline Member
    Join Date
    Mar 2010
    Posts
    50
    Rep Power
    0

    Default

    ava.lang.NullPointerException
    at Select.selectFilters(Select.java:93)
    at MAIN.main(MAIN.java:28)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,733
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by miko5054 View Post
    im tring to wite a jdbc class but greeting a NULL pointer exception on this line

    resultSet = preparedStatement.executeQuery(sql);
    Your preparedStatement is null; you initialized it to that value and never assigned another value to it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Null pointer exception
    By samuel.roshni in forum Java Servlet
    Replies: 14
    Last Post: 01-22-2011, 03:25 PM
  2. Null pointer Exception
    By peiceonly in forum New To Java
    Replies: 8
    Last Post: 09-05-2010, 07:48 PM
  3. Null pointer exception
    By talha06 in forum JDBC
    Replies: 5
    Last Post: 07-14-2009, 02:12 AM
  4. null pointer exception
    By anthonym2121 in forum New To Java
    Replies: 7
    Last Post: 04-06-2009, 04:25 AM
  5. Null pointer exception
    By Stephenmak in forum New To Java
    Replies: 5
    Last Post: 04-01-2009, 03:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •