Oracle 11g communication with java in Netbeans 7.1

I have successfully linked my Oracle 11g XE database 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 the table employee(fname,lname,ssn)

, get all the records and display 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 am getting the following error:

Error: java.sql.SQLSyntaxErrorException: ORA-00911: Invalid character

This may be due to the fact that we cannot access multiple lines in oracle.

How can I access a table employee

in Java?

+3


source to share


1 answer


Remove the semicolon from the request.

String qq = "select fname,ssn from employee where lname='tank'";

      



By the way, all of the cast (Statement)

and (ResultSet)

do not need.

+4


source







All Articles