I created a connection with a data base with Java and I would like to display data from two tables.
In the query statement I used a JOIN command but i am struggling with a syntax error.
Was hoping for some advice in regards to this.
try
{
Class.forName(driverName);
connection = DriverManager.getConnection(SourceURL, user, password);
Statement listDisplay = connection.createStatement();
ResultSet displayAll = listDisplay.executeQuery("SELECT AnimalType.typeID, AnimalType.description, Animal.name "
+"FROM Animal "
+"JOIN AnimalType "
+"ON AnimalType.typeID = Animal.typeIDForeign");
while(displayAll.next())
{
int typeId = displayAll.getInt(1);
String description = displayAll.getString(2);
String name = displayAll.getString(3);
System.out.println(typeId + " " + description + " " + name);
}
connection.close();
}
catch(SQLException sql)
{
JOptionPane.showMessageDialog(null, sql.toString());
}
catch(ClassNotFoundException exe)
{
JOptionPane.showMessageDialog(null, exe.toString());
}
Will it work what I am trying to do here.?
regards
Arian
I normally do it somewhat like this: