Tuesday, 15 March 2016

SQL Join with 3 tables?

SQL JOIN With 3 Tables Example :
Example#1
SELECT  t1.column1, t2.column2, t3.column3
FROM table1 t1 INNER JOIN
table2 t2 ON t1.column1 = t2.column2  AND t1.column2 = t2.column3
LEFT OUTER JOIN  table3 t3 ON t2.column2= t3.column2 AND t2.column3 = t3.column3
WHERE  t1.column1=45;

Example#2
SELECT  t1.column1, t2.column2, t3.column3
FROM table1 t1 INNER JOIN
table2 t2 ON t1.column1 = t2.column2  AND t1.column2 = t2.column3
INNER JOIN  table3 t3 ON t2.column2= t3.column2 AND t2.column3 = t3.column3
WHERE  t1.column1=45;
Note: SQL join works from left to right. In this case, it will first join table1 with table2 and then result of this will get joined with table3



Thursday, 3 March 2016

Java Properties File: Reading config.properties Values in JAVA

Reading config.properties Values in JAVA :
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream("config.properties");
// load a properties file
prop.load(input);
// get the property value and print it out
System.out.println(prop.getProperty("database"));
System.out.println(prop.getProperty("dbuser"));
System.out.println(prop.getProperty("dbpassword"));
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}