I'm trying to get the values from a database and insert them into an array and return, but it gives me an error: "cannot find symbol for variable str in return statement".
public class getDates {
public static Date[] Dates(){
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "GreetingCard";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("select date from profile");
ResultSetMetaData metadata = rs.getMetaData();
int columnCount = metadata.getColumnCount();
Date[] str = new Date[columnCount];
int a=0;
//getting the dates from database to an array
while(rs.next()){
str[a++]=rs.getDate("date");
}
}
catch(Exception e){
System.out.println(e);
}
//returning the array str
return str;
}
}