Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Understanding NUllPointer Exceptions

843789Jun 23 2010 — edited Jun 23 2010
I have this piece of code below that throws a null-pointer exception on the line of

stmt = conn.createStatement();

I have school projects from last semester that use this very statement and they don't get null-pointer exceptions when run.
So I am wondering if you can tell me what's going on behind the scenes.
public class Commands {
	
	private  Connection 	conn;
	private  Statement		stmt;
	private  ResultSet		results;
	
	/**
	 *  Create a Table to which the user has chosen to imput
	 *  information.
	 */
	
	public void createTable()
	{
		try 
		{
			stmt = conn.createStatement();
			String table = JOptionPane.showInputDialog("Enter in the table and values for that table: ");
			String query = table;
                        //it is assumed the user will type in CREATE tabel_name{value varchar2(9)} <- sample tabel.

		} 
		
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
	}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 21 2010
Added on Jun 23 2010
12 comments
242 views