Connecting to a database table
I was successful writing down the java code that connects to my JavaDB.(Am using NetBeans IDE).I want to retrieve content from my table called workers(Under the APP' SCHEMA) but that isnt possible.When I run my code,the following happens.
'Schema 'KMUGALAASI' doesnt exit'.
BUILD SUCCESSFUL.
Can anyone tell mi what that means and how can I solve that problem? So that I can retrieve contents FROM MY TABLE(Workers with columns-ID,First_Name,Last_Name and Job_Title).Have a look at my code.
package database_console;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
public class DBConnect {
public static void main(String[] args) {
try {
String host = "jdbc:derby://localhost:1527/Employees";
String uName = "kmugalaasi";
String uPass = "GETAFE";
Connection con = DriverManager.getConnection(host,uName,uPass);
Statement stmt = con.createStatement();
String SQL = "SELECT * FROM Workers";
ResultSet rs = stmt.executeQuery(SQL);
while (rs.next()) {
int id_col = rs.getInt("ID");
String first_name = rs.getString("First_Name");
String last_name = rs.getString("Last_Name");
String job = rs.getString("Job_Title");
String p = id_col + " " + first_name + " " + last_name + " " + job;
System.out.println(p);
}
}
catch (SQLException err) {
System.out.println(err.getMessage());
}
}
}