I have a database connection which works well when using static final Strings, i.e. DATABASE_NAME = "test";
I want to make this a little more dynamic so I created a text box on my JFrame
Then I created a method to return the String of txtDBName as follows:Code:txtDBName = new JTextField(); txtDBName.setText("");
I then want to use the value in txtDBName as the name of my database in my connection string as follows:Code:public String getDatabaseName() { return txtDBName.getText().trim(); }
I also tried the following without any luckCode:conn=DriverManager.getConnection(dbView.DATABASE_URL + dbView.getDatabaseName() , username, password);
but I keep getting a nullPointerExceptionCode:conn=DriverManager.getConnection(dbView.DATABASE_URL + dbView.txtDBName.getText(), username, password);
Can someone shed some light on this for me?
Thanks




Reply With Quote