I was trying to access my database from a java program and created one table to see if it works.
The program compiled perfectly fine, yet the table doesn't appear in the program output. What's wrong?
package db_cliinic;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
public class DB_Cliinic {
public static void main(String[] args) {
Connection con = null;
Statement stat = null;
ResultSet res = null;
String q = "select * from DB.EMPLOYEE";
try {
con = DriverManager.getConnection("jdbc:derby://localhost1527/VetClinic", "DB", "123456");
stat = con.createStatement();
res = stat.executeQuery(q);
while (res.next()) {
char id = (char) res.getCharacterStream("EMP_ID").read();
String name = res.getString("NAME");
char phone =(char) res.getCharacterStream("PHONE_NUMBER").read();
String Edu = res.getString("EDUCATION_LEVEL");
double sal = res.getDouble("SALARY");
String role = res.getString("ROLE");
char sex = (char) res.getCharacterStream("SEX").read();
String addr = res.getString("ADDRESS");
char crn = (char) res.getCharacterStream("ECRN").read();
char super_id = (char) res.getCharacterStream("SUPER_ID").read();
System.out.println(" "+id+" "+name+" "+phone+" "+Edu+" "+sal+" "+role+" "+sex+" "+addr+" "+crn+super_id);
}
}
catch (SQLException e){
} catch (IOException ex) {
Logger.getLogger(DB_clinic.class.getName()).log(Level.SEVERE, null, ex); } } }