I have successfully connected my Oracle 11g XEdatabase with java in Netbeans 7.1.
Class.forName("oracle.jdbc.OracleDriver");
System.out.println("DRIVER LOADED!");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "acpsa") ;
System.out.println("CONNECTION ESTABLISHED!");
Now I want to access a table employee(fname,lname,ssn), retrieving all records and displaying them.
When I add this code:
Statement stmt;
stmt=(Statement)conn.createStatement();
String qq = "select fname,ssn from employee where lname='tank';";
ResultSet rs = (ResultSet)stmt.executeQuery(qq);
while(rs.next()){
System.out.println(rs.getString("fname") + "\t" + rs.getString("ssn"));
}
I get the following error:
Error :java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
This might be due to the fact the we can't access multiple rows in oracle.
How can I access the employee table in Java?
Remove the semicolon from the query.
String qq = "select fname,ssn from employee where lname='tank'";
By the way, all those casts (Statement) and (ResultSet) are unnecessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With