× 274612 Retrieving and displaying Msql database data on a textarea using a Java application
I have created a MySQL database with 4 columns.I want to read the second column of the database and display it on a text area. I have method display() that is called when i click on a button. The code for the method is:
public void display(){
db=new Database();
try{
int n=Integer.parseInt(field.getText());
ResultSet rset=Database.conn.createStatement().executeQuery("select * from mymusic where trackNumber like'"+n+"'");
while(rset.next()){
area.setText(rset.getString("Songlocation"));
}
rset.close();
}catch(SQLException e){
JOptionPane.showMessageDialog(this,"Database error","Warning",JOptionPane.ERROR_MESSAGE);
}
catch(NumberFormatException numfom)
{
JOptionPane.showMessageDialog(this,"Invalid Entry","Warning",JOptionPane.ERROR_MESSAGE);
}
}
A Exception in thread "AWT-EventQueue-0" java.Lang.NullPointerException is thrown when i execute the code and of cos no display. The database connection is perfect since i can update the database successfully. assist me print the data on the text-area.