3

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.