Java display records from a table based on records in other tables












-1














I'm very new to using databases and SQL in general and I'm having some trouble figuring out a function that will allow me to display records from a table in my jdbc database based on data from other tables in the database. I will illustrate below:



Example of "DEMANDS" table (column headers, "ID" is the primary key):



NAME|ADDRESS|DESTINATION|DATE|TIME|ID


Example of "DRIVERS" table ("REGISTRATION" is the primary key):



USERNAME|PASSWORD|REGISTRATION|NAME


Example of "JOURNEY" table ("JID" is the primary key,"REGISTRATION" is a foreign key)



JID|NAME|ADDRESS|DESTINATION|DISTANCE|REGISTRATION|DATE|TIME|STATUS


Below is the code that I have that is used to display tables on a jsp file:



public String retrieve(String query) throws SQLException {
select(query);
return makeTable(rsToList());//results;
}

private void select(String query){
try {
statement = connection.createStatement();
rs = statement.executeQuery(query);
//statement.close();
}
catch(SQLException e) {
System.out.println("way way"+e);
//results = e.toString();
}
}

private String makeTable(ArrayList list) {
StringBuilder b = new StringBuilder();
String row;
b.append("<table border="3">");
for (Object s : list) {
b.append("<tr>");
row = (String) s;
for (String row1 : row) {
b.append("<td>");
b.append(row1);
b.append("</td>");
}
b.append("</tr>n");
} // for
b.append("</table>");
return b.toString();
}//makeHtmlTable

private ArrayList rsToList() throws SQLException {
ArrayList aList = new ArrayList();
ResultSetMetaData metaData = rs.getMetaData();
int count = metaData.getColumnCount(); //number of column
String columnName = new String[count];

for (int i = 1; i <= count; i++)
{
columnName[i-1] = metaData.getColumnLabel(i);
}
aList.add(columnName);

int cols = rs.getMetaData().getColumnCount();
while (rs.next()) {
String s = new String[cols];
for (int i = 1; i <= cols; i++) {
s[i-1] = rs.getString(i);
}
aList.add(s);
} // while
return aList;
} //rsToList


All of this code works fine and if I pass in a query into the "Retrieve" function such as:



String query = "select * from DRIVERS";


It will display all of the records of the "DRIVERS" table.



What I am wanting to do though, is only list drivers from the driver table that are available at the time specified in the demand (meaning their registration is not currently in a record in the journey table at the same time as the demand) If possible, I would also only like to display the "NAME" and "REGISTRATION" columns as oppose to the whole record.



I would really appreciate some help with this as I've searched around for solutions for quite some time and have not been able to work out a function that will achieve the desired outcome.



Cheers,



Creation of tables script:



-- --------------------------------------------------------
--DROP Table Demands;
CREATE TABLE Demands (
Name varchar(20),
Address varchar(60),
Destination varchar(60),
Date date DEFAULT NULL,
Time time DEFAULT NULL,
Status varchar(15) NOT NULL,
id INT primary key
);


-- --------------------------------------------------------
--DROP Table Drivers;
CREATE TABLE Drivers (
username varchar(20),
password varchar(20),
Registration varchar(10),
Name varchar(20),
PRIMARY KEY (Registration)
);


-- --------------------------------------------------------

--DROP Table Journey;
CREATE TABLE Journey (
jid INT primary key
Destination varchar(60),
Distance integer NOT NULL DEFAULT 1,
Registration varchar(10) NOT NULL,
Date date NOT NULL,
Time time DEFAULT NULL
);









share|improve this question
























  • Possible duplicate of SQL query to find record with ID not in another table. Please remember to do research before asking questions here. See How to ask a good question.
    – xtratic
    Nov 20 at 15:40












  • Can you provide the creation script of your model (CREATE TABLE statements)?
    – Ahmad Shahwan
    Nov 20 at 15:48










  • @Ahmad Shahwan I will edit my post to show this, cheers!
    – Seano989
    Nov 20 at 15:52










  • I updated my answer according to your creation script.
    – Ahmad Shahwan
    Nov 20 at 16:03
















-1














I'm very new to using databases and SQL in general and I'm having some trouble figuring out a function that will allow me to display records from a table in my jdbc database based on data from other tables in the database. I will illustrate below:



Example of "DEMANDS" table (column headers, "ID" is the primary key):



NAME|ADDRESS|DESTINATION|DATE|TIME|ID


Example of "DRIVERS" table ("REGISTRATION" is the primary key):



USERNAME|PASSWORD|REGISTRATION|NAME


Example of "JOURNEY" table ("JID" is the primary key,"REGISTRATION" is a foreign key)



JID|NAME|ADDRESS|DESTINATION|DISTANCE|REGISTRATION|DATE|TIME|STATUS


Below is the code that I have that is used to display tables on a jsp file:



public String retrieve(String query) throws SQLException {
select(query);
return makeTable(rsToList());//results;
}

private void select(String query){
try {
statement = connection.createStatement();
rs = statement.executeQuery(query);
//statement.close();
}
catch(SQLException e) {
System.out.println("way way"+e);
//results = e.toString();
}
}

private String makeTable(ArrayList list) {
StringBuilder b = new StringBuilder();
String row;
b.append("<table border="3">");
for (Object s : list) {
b.append("<tr>");
row = (String) s;
for (String row1 : row) {
b.append("<td>");
b.append(row1);
b.append("</td>");
}
b.append("</tr>n");
} // for
b.append("</table>");
return b.toString();
}//makeHtmlTable

private ArrayList rsToList() throws SQLException {
ArrayList aList = new ArrayList();
ResultSetMetaData metaData = rs.getMetaData();
int count = metaData.getColumnCount(); //number of column
String columnName = new String[count];

for (int i = 1; i <= count; i++)
{
columnName[i-1] = metaData.getColumnLabel(i);
}
aList.add(columnName);

int cols = rs.getMetaData().getColumnCount();
while (rs.next()) {
String s = new String[cols];
for (int i = 1; i <= cols; i++) {
s[i-1] = rs.getString(i);
}
aList.add(s);
} // while
return aList;
} //rsToList


All of this code works fine and if I pass in a query into the "Retrieve" function such as:



String query = "select * from DRIVERS";


It will display all of the records of the "DRIVERS" table.



What I am wanting to do though, is only list drivers from the driver table that are available at the time specified in the demand (meaning their registration is not currently in a record in the journey table at the same time as the demand) If possible, I would also only like to display the "NAME" and "REGISTRATION" columns as oppose to the whole record.



I would really appreciate some help with this as I've searched around for solutions for quite some time and have not been able to work out a function that will achieve the desired outcome.



Cheers,



Creation of tables script:



-- --------------------------------------------------------
--DROP Table Demands;
CREATE TABLE Demands (
Name varchar(20),
Address varchar(60),
Destination varchar(60),
Date date DEFAULT NULL,
Time time DEFAULT NULL,
Status varchar(15) NOT NULL,
id INT primary key
);


-- --------------------------------------------------------
--DROP Table Drivers;
CREATE TABLE Drivers (
username varchar(20),
password varchar(20),
Registration varchar(10),
Name varchar(20),
PRIMARY KEY (Registration)
);


-- --------------------------------------------------------

--DROP Table Journey;
CREATE TABLE Journey (
jid INT primary key
Destination varchar(60),
Distance integer NOT NULL DEFAULT 1,
Registration varchar(10) NOT NULL,
Date date NOT NULL,
Time time DEFAULT NULL
);









share|improve this question
























  • Possible duplicate of SQL query to find record with ID not in another table. Please remember to do research before asking questions here. See How to ask a good question.
    – xtratic
    Nov 20 at 15:40












  • Can you provide the creation script of your model (CREATE TABLE statements)?
    – Ahmad Shahwan
    Nov 20 at 15:48










  • @Ahmad Shahwan I will edit my post to show this, cheers!
    – Seano989
    Nov 20 at 15:52










  • I updated my answer according to your creation script.
    – Ahmad Shahwan
    Nov 20 at 16:03














-1












-1








-1







I'm very new to using databases and SQL in general and I'm having some trouble figuring out a function that will allow me to display records from a table in my jdbc database based on data from other tables in the database. I will illustrate below:



Example of "DEMANDS" table (column headers, "ID" is the primary key):



NAME|ADDRESS|DESTINATION|DATE|TIME|ID


Example of "DRIVERS" table ("REGISTRATION" is the primary key):



USERNAME|PASSWORD|REGISTRATION|NAME


Example of "JOURNEY" table ("JID" is the primary key,"REGISTRATION" is a foreign key)



JID|NAME|ADDRESS|DESTINATION|DISTANCE|REGISTRATION|DATE|TIME|STATUS


Below is the code that I have that is used to display tables on a jsp file:



public String retrieve(String query) throws SQLException {
select(query);
return makeTable(rsToList());//results;
}

private void select(String query){
try {
statement = connection.createStatement();
rs = statement.executeQuery(query);
//statement.close();
}
catch(SQLException e) {
System.out.println("way way"+e);
//results = e.toString();
}
}

private String makeTable(ArrayList list) {
StringBuilder b = new StringBuilder();
String row;
b.append("<table border="3">");
for (Object s : list) {
b.append("<tr>");
row = (String) s;
for (String row1 : row) {
b.append("<td>");
b.append(row1);
b.append("</td>");
}
b.append("</tr>n");
} // for
b.append("</table>");
return b.toString();
}//makeHtmlTable

private ArrayList rsToList() throws SQLException {
ArrayList aList = new ArrayList();
ResultSetMetaData metaData = rs.getMetaData();
int count = metaData.getColumnCount(); //number of column
String columnName = new String[count];

for (int i = 1; i <= count; i++)
{
columnName[i-1] = metaData.getColumnLabel(i);
}
aList.add(columnName);

int cols = rs.getMetaData().getColumnCount();
while (rs.next()) {
String s = new String[cols];
for (int i = 1; i <= cols; i++) {
s[i-1] = rs.getString(i);
}
aList.add(s);
} // while
return aList;
} //rsToList


All of this code works fine and if I pass in a query into the "Retrieve" function such as:



String query = "select * from DRIVERS";


It will display all of the records of the "DRIVERS" table.



What I am wanting to do though, is only list drivers from the driver table that are available at the time specified in the demand (meaning their registration is not currently in a record in the journey table at the same time as the demand) If possible, I would also only like to display the "NAME" and "REGISTRATION" columns as oppose to the whole record.



I would really appreciate some help with this as I've searched around for solutions for quite some time and have not been able to work out a function that will achieve the desired outcome.



Cheers,



Creation of tables script:



-- --------------------------------------------------------
--DROP Table Demands;
CREATE TABLE Demands (
Name varchar(20),
Address varchar(60),
Destination varchar(60),
Date date DEFAULT NULL,
Time time DEFAULT NULL,
Status varchar(15) NOT NULL,
id INT primary key
);


-- --------------------------------------------------------
--DROP Table Drivers;
CREATE TABLE Drivers (
username varchar(20),
password varchar(20),
Registration varchar(10),
Name varchar(20),
PRIMARY KEY (Registration)
);


-- --------------------------------------------------------

--DROP Table Journey;
CREATE TABLE Journey (
jid INT primary key
Destination varchar(60),
Distance integer NOT NULL DEFAULT 1,
Registration varchar(10) NOT NULL,
Date date NOT NULL,
Time time DEFAULT NULL
);









share|improve this question















I'm very new to using databases and SQL in general and I'm having some trouble figuring out a function that will allow me to display records from a table in my jdbc database based on data from other tables in the database. I will illustrate below:



Example of "DEMANDS" table (column headers, "ID" is the primary key):



NAME|ADDRESS|DESTINATION|DATE|TIME|ID


Example of "DRIVERS" table ("REGISTRATION" is the primary key):



USERNAME|PASSWORD|REGISTRATION|NAME


Example of "JOURNEY" table ("JID" is the primary key,"REGISTRATION" is a foreign key)



JID|NAME|ADDRESS|DESTINATION|DISTANCE|REGISTRATION|DATE|TIME|STATUS


Below is the code that I have that is used to display tables on a jsp file:



public String retrieve(String query) throws SQLException {
select(query);
return makeTable(rsToList());//results;
}

private void select(String query){
try {
statement = connection.createStatement();
rs = statement.executeQuery(query);
//statement.close();
}
catch(SQLException e) {
System.out.println("way way"+e);
//results = e.toString();
}
}

private String makeTable(ArrayList list) {
StringBuilder b = new StringBuilder();
String row;
b.append("<table border="3">");
for (Object s : list) {
b.append("<tr>");
row = (String) s;
for (String row1 : row) {
b.append("<td>");
b.append(row1);
b.append("</td>");
}
b.append("</tr>n");
} // for
b.append("</table>");
return b.toString();
}//makeHtmlTable

private ArrayList rsToList() throws SQLException {
ArrayList aList = new ArrayList();
ResultSetMetaData metaData = rs.getMetaData();
int count = metaData.getColumnCount(); //number of column
String columnName = new String[count];

for (int i = 1; i <= count; i++)
{
columnName[i-1] = metaData.getColumnLabel(i);
}
aList.add(columnName);

int cols = rs.getMetaData().getColumnCount();
while (rs.next()) {
String s = new String[cols];
for (int i = 1; i <= cols; i++) {
s[i-1] = rs.getString(i);
}
aList.add(s);
} // while
return aList;
} //rsToList


All of this code works fine and if I pass in a query into the "Retrieve" function such as:



String query = "select * from DRIVERS";


It will display all of the records of the "DRIVERS" table.



What I am wanting to do though, is only list drivers from the driver table that are available at the time specified in the demand (meaning their registration is not currently in a record in the journey table at the same time as the demand) If possible, I would also only like to display the "NAME" and "REGISTRATION" columns as oppose to the whole record.



I would really appreciate some help with this as I've searched around for solutions for quite some time and have not been able to work out a function that will achieve the desired outcome.



Cheers,



Creation of tables script:



-- --------------------------------------------------------
--DROP Table Demands;
CREATE TABLE Demands (
Name varchar(20),
Address varchar(60),
Destination varchar(60),
Date date DEFAULT NULL,
Time time DEFAULT NULL,
Status varchar(15) NOT NULL,
id INT primary key
);


-- --------------------------------------------------------
--DROP Table Drivers;
CREATE TABLE Drivers (
username varchar(20),
password varchar(20),
Registration varchar(10),
Name varchar(20),
PRIMARY KEY (Registration)
);


-- --------------------------------------------------------

--DROP Table Journey;
CREATE TABLE Journey (
jid INT primary key
Destination varchar(60),
Distance integer NOT NULL DEFAULT 1,
Registration varchar(10) NOT NULL,
Date date NOT NULL,
Time time DEFAULT NULL
);






java mysql sql jdbc netbeans






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 15:53

























asked Nov 20 at 15:31









Seano989

83




83












  • Possible duplicate of SQL query to find record with ID not in another table. Please remember to do research before asking questions here. See How to ask a good question.
    – xtratic
    Nov 20 at 15:40












  • Can you provide the creation script of your model (CREATE TABLE statements)?
    – Ahmad Shahwan
    Nov 20 at 15:48










  • @Ahmad Shahwan I will edit my post to show this, cheers!
    – Seano989
    Nov 20 at 15:52










  • I updated my answer according to your creation script.
    – Ahmad Shahwan
    Nov 20 at 16:03


















  • Possible duplicate of SQL query to find record with ID not in another table. Please remember to do research before asking questions here. See How to ask a good question.
    – xtratic
    Nov 20 at 15:40












  • Can you provide the creation script of your model (CREATE TABLE statements)?
    – Ahmad Shahwan
    Nov 20 at 15:48










  • @Ahmad Shahwan I will edit my post to show this, cheers!
    – Seano989
    Nov 20 at 15:52










  • I updated my answer according to your creation script.
    – Ahmad Shahwan
    Nov 20 at 16:03
















Possible duplicate of SQL query to find record with ID not in another table. Please remember to do research before asking questions here. See How to ask a good question.
– xtratic
Nov 20 at 15:40






Possible duplicate of SQL query to find record with ID not in another table. Please remember to do research before asking questions here. See How to ask a good question.
– xtratic
Nov 20 at 15:40














Can you provide the creation script of your model (CREATE TABLE statements)?
– Ahmad Shahwan
Nov 20 at 15:48




Can you provide the creation script of your model (CREATE TABLE statements)?
– Ahmad Shahwan
Nov 20 at 15:48












@Ahmad Shahwan I will edit my post to show this, cheers!
– Seano989
Nov 20 at 15:52




@Ahmad Shahwan I will edit my post to show this, cheers!
– Seano989
Nov 20 at 15:52












I updated my answer according to your creation script.
– Ahmad Shahwan
Nov 20 at 16:03




I updated my answer according to your creation script.
– Ahmad Shahwan
Nov 20 at 16:03












1 Answer
1






active

oldest

votes


















0














The following query may answer your question.



SELECT Drivers.Name, Drivers.Registration
FROM Drivers
LEFT JOIN Journey ON Journey.Registration = Drivers.Registration
LEFT JOIN Demands ON Demands.Date = Journey.Date
WHERE Demands.id IS NULL;


This joins JOURNEY and DRIVER based on the foreign key relation. It then outer-joins DEMANDS and JOURNEY based on an implicit relation that is DATE. Finally we only keep records that fail the outer join condition.



The model has a major flaw though as the relation between DEMANDS and JOURNEY is based on a field of type Date, as far as one can tell by what your provided.






share|improve this answer























  • Hey thanks for the reply! Would you recommend that I maybe include a foreign key in JOURNEY that references the ID in DEMANDS? Would that be a better solution?
    – Seano989
    Nov 20 at 15:56










  • If you have a one-to-many relationship, yes (that is each journey has only one demand). Otherwise (a journey may have one or more demand) you would have to create a new table that "breaks" the many-to-many relationship.
    – Ahmad Shahwan
    Nov 20 at 16:05










  • I tried to pass in the query as you stated however, I got an error that says "java.lang.NullPointerException"
    – Seano989
    Nov 20 at 16:05










  • Your NullPointerException may be due to a null value in your tables, ex. name in Driver.
    – Ahmad Shahwan
    Nov 20 at 16:23






  • 1




    Please ignore my previous comments, I implemented your query incorrectly, I have now implemented it correctly and it works perfectly! I really appreciate the help as i'm completely new to all this SQL and relational database business and what you've shown me has helped me grasp some concepts a little better
    – Seano989
    Nov 20 at 16:37











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396376%2fjava-display-records-from-a-table-based-on-records-in-other-tables%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The following query may answer your question.



SELECT Drivers.Name, Drivers.Registration
FROM Drivers
LEFT JOIN Journey ON Journey.Registration = Drivers.Registration
LEFT JOIN Demands ON Demands.Date = Journey.Date
WHERE Demands.id IS NULL;


This joins JOURNEY and DRIVER based on the foreign key relation. It then outer-joins DEMANDS and JOURNEY based on an implicit relation that is DATE. Finally we only keep records that fail the outer join condition.



The model has a major flaw though as the relation between DEMANDS and JOURNEY is based on a field of type Date, as far as one can tell by what your provided.






share|improve this answer























  • Hey thanks for the reply! Would you recommend that I maybe include a foreign key in JOURNEY that references the ID in DEMANDS? Would that be a better solution?
    – Seano989
    Nov 20 at 15:56










  • If you have a one-to-many relationship, yes (that is each journey has only one demand). Otherwise (a journey may have one or more demand) you would have to create a new table that "breaks" the many-to-many relationship.
    – Ahmad Shahwan
    Nov 20 at 16:05










  • I tried to pass in the query as you stated however, I got an error that says "java.lang.NullPointerException"
    – Seano989
    Nov 20 at 16:05










  • Your NullPointerException may be due to a null value in your tables, ex. name in Driver.
    – Ahmad Shahwan
    Nov 20 at 16:23






  • 1




    Please ignore my previous comments, I implemented your query incorrectly, I have now implemented it correctly and it works perfectly! I really appreciate the help as i'm completely new to all this SQL and relational database business and what you've shown me has helped me grasp some concepts a little better
    – Seano989
    Nov 20 at 16:37
















0














The following query may answer your question.



SELECT Drivers.Name, Drivers.Registration
FROM Drivers
LEFT JOIN Journey ON Journey.Registration = Drivers.Registration
LEFT JOIN Demands ON Demands.Date = Journey.Date
WHERE Demands.id IS NULL;


This joins JOURNEY and DRIVER based on the foreign key relation. It then outer-joins DEMANDS and JOURNEY based on an implicit relation that is DATE. Finally we only keep records that fail the outer join condition.



The model has a major flaw though as the relation between DEMANDS and JOURNEY is based on a field of type Date, as far as one can tell by what your provided.






share|improve this answer























  • Hey thanks for the reply! Would you recommend that I maybe include a foreign key in JOURNEY that references the ID in DEMANDS? Would that be a better solution?
    – Seano989
    Nov 20 at 15:56










  • If you have a one-to-many relationship, yes (that is each journey has only one demand). Otherwise (a journey may have one or more demand) you would have to create a new table that "breaks" the many-to-many relationship.
    – Ahmad Shahwan
    Nov 20 at 16:05










  • I tried to pass in the query as you stated however, I got an error that says "java.lang.NullPointerException"
    – Seano989
    Nov 20 at 16:05










  • Your NullPointerException may be due to a null value in your tables, ex. name in Driver.
    – Ahmad Shahwan
    Nov 20 at 16:23






  • 1




    Please ignore my previous comments, I implemented your query incorrectly, I have now implemented it correctly and it works perfectly! I really appreciate the help as i'm completely new to all this SQL and relational database business and what you've shown me has helped me grasp some concepts a little better
    – Seano989
    Nov 20 at 16:37














0












0








0






The following query may answer your question.



SELECT Drivers.Name, Drivers.Registration
FROM Drivers
LEFT JOIN Journey ON Journey.Registration = Drivers.Registration
LEFT JOIN Demands ON Demands.Date = Journey.Date
WHERE Demands.id IS NULL;


This joins JOURNEY and DRIVER based on the foreign key relation. It then outer-joins DEMANDS and JOURNEY based on an implicit relation that is DATE. Finally we only keep records that fail the outer join condition.



The model has a major flaw though as the relation between DEMANDS and JOURNEY is based on a field of type Date, as far as one can tell by what your provided.






share|improve this answer














The following query may answer your question.



SELECT Drivers.Name, Drivers.Registration
FROM Drivers
LEFT JOIN Journey ON Journey.Registration = Drivers.Registration
LEFT JOIN Demands ON Demands.Date = Journey.Date
WHERE Demands.id IS NULL;


This joins JOURNEY and DRIVER based on the foreign key relation. It then outer-joins DEMANDS and JOURNEY based on an implicit relation that is DATE. Finally we only keep records that fail the outer join condition.



The model has a major flaw though as the relation between DEMANDS and JOURNEY is based on a field of type Date, as far as one can tell by what your provided.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 at 16:34

























answered Nov 20 at 15:47









Ahmad Shahwan

485213




485213












  • Hey thanks for the reply! Would you recommend that I maybe include a foreign key in JOURNEY that references the ID in DEMANDS? Would that be a better solution?
    – Seano989
    Nov 20 at 15:56










  • If you have a one-to-many relationship, yes (that is each journey has only one demand). Otherwise (a journey may have one or more demand) you would have to create a new table that "breaks" the many-to-many relationship.
    – Ahmad Shahwan
    Nov 20 at 16:05










  • I tried to pass in the query as you stated however, I got an error that says "java.lang.NullPointerException"
    – Seano989
    Nov 20 at 16:05










  • Your NullPointerException may be due to a null value in your tables, ex. name in Driver.
    – Ahmad Shahwan
    Nov 20 at 16:23






  • 1




    Please ignore my previous comments, I implemented your query incorrectly, I have now implemented it correctly and it works perfectly! I really appreciate the help as i'm completely new to all this SQL and relational database business and what you've shown me has helped me grasp some concepts a little better
    – Seano989
    Nov 20 at 16:37


















  • Hey thanks for the reply! Would you recommend that I maybe include a foreign key in JOURNEY that references the ID in DEMANDS? Would that be a better solution?
    – Seano989
    Nov 20 at 15:56










  • If you have a one-to-many relationship, yes (that is each journey has only one demand). Otherwise (a journey may have one or more demand) you would have to create a new table that "breaks" the many-to-many relationship.
    – Ahmad Shahwan
    Nov 20 at 16:05










  • I tried to pass in the query as you stated however, I got an error that says "java.lang.NullPointerException"
    – Seano989
    Nov 20 at 16:05










  • Your NullPointerException may be due to a null value in your tables, ex. name in Driver.
    – Ahmad Shahwan
    Nov 20 at 16:23






  • 1




    Please ignore my previous comments, I implemented your query incorrectly, I have now implemented it correctly and it works perfectly! I really appreciate the help as i'm completely new to all this SQL and relational database business and what you've shown me has helped me grasp some concepts a little better
    – Seano989
    Nov 20 at 16:37
















Hey thanks for the reply! Would you recommend that I maybe include a foreign key in JOURNEY that references the ID in DEMANDS? Would that be a better solution?
– Seano989
Nov 20 at 15:56




Hey thanks for the reply! Would you recommend that I maybe include a foreign key in JOURNEY that references the ID in DEMANDS? Would that be a better solution?
– Seano989
Nov 20 at 15:56












If you have a one-to-many relationship, yes (that is each journey has only one demand). Otherwise (a journey may have one or more demand) you would have to create a new table that "breaks" the many-to-many relationship.
– Ahmad Shahwan
Nov 20 at 16:05




If you have a one-to-many relationship, yes (that is each journey has only one demand). Otherwise (a journey may have one or more demand) you would have to create a new table that "breaks" the many-to-many relationship.
– Ahmad Shahwan
Nov 20 at 16:05












I tried to pass in the query as you stated however, I got an error that says "java.lang.NullPointerException"
– Seano989
Nov 20 at 16:05




I tried to pass in the query as you stated however, I got an error that says "java.lang.NullPointerException"
– Seano989
Nov 20 at 16:05












Your NullPointerException may be due to a null value in your tables, ex. name in Driver.
– Ahmad Shahwan
Nov 20 at 16:23




Your NullPointerException may be due to a null value in your tables, ex. name in Driver.
– Ahmad Shahwan
Nov 20 at 16:23




1




1




Please ignore my previous comments, I implemented your query incorrectly, I have now implemented it correctly and it works perfectly! I really appreciate the help as i'm completely new to all this SQL and relational database business and what you've shown me has helped me grasp some concepts a little better
– Seano989
Nov 20 at 16:37




Please ignore my previous comments, I implemented your query incorrectly, I have now implemented it correctly and it works perfectly! I really appreciate the help as i'm completely new to all this SQL and relational database business and what you've shown me has helped me grasp some concepts a little better
– Seano989
Nov 20 at 16:37


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396376%2fjava-display-records-from-a-table-based-on-records-in-other-tables%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin