I have the following code which appears to work correctly but it does not display any values for the personCode string. PERSON_CODE is a VARCHAR2 in an Oracle 9i database.
I am using Java SE 1.7 and ojdbc7.jar for my project. I am new to Java can anybody give me some help with this?
private static void GetEmployee(String input) {
String output = "";
Connection con=null;
PreparedStatement stmt = null;
String sql ="SELECT ALL BADGE_NUMBER, PERSON_CODE FROM BADGETABLE WHERE BADGE_NUMBER = ?";
try {
//load driver
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:username/password@host:1521:database");
//declaring statement
stmt = con.prepareStatement(sql);
stmt.setString(1, input);
// execute query
ResultSet rows = stmt.executeQuery();
int i = 0;
while(rows.next()) {
i++;
String badgeCode = rows.getString(1);
String personCode = rows.getString(2);
String personType = rows.getString(3);
System.out.println("Badge number: " + badgeCode);
System.out.println("Employee ID: " + personCode);
}
System.out.println("Number of results: " + i);
rows.close(); // All done with that resultset
stmt.close(); // All done with that statement
con.close(); // All done with that DB connection
}
catch (SQLException e) {
System.err.println(e);
}
catch (ClassNotFoundException e) {
System.err.println(e);
}
return;
}
ALLisn't a problem, it's just enforcing the default behaviour - i.e. notDISTINCT. Redundant, really, but valid.