sweet dreams sweet dreams - 1 year ago 133
Java Question

Understanding mysterious Oracle JDBC errors - ORA-00911: invalid character

I am making Java 1.6-JDBC-Oracle 11 code. I created a table called employee with id,name and age. I am getting the error - ORA-00911: invalid character. How can I fix this ?

Here is my code-

import java.sql.*;
import java.util.Properties;
import java.io.IOException;
import java.io.FileInputStream;

public class HelloOracle {

static String query=
"SELECT emp_id, emp_name, emp_age " +
"FROM employee;";

public static void main(String[]args)
String username = "";
String password = "";
Properties prop = new Properties();
FileInputStream fis = new FileInputStream("Login.properties");
}catch(IOException ex){ex.printStackTrace();}

username = prop.getProperty("username").trim();
password = prop.getProperty("password").trim();


Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/xe", username, password);

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(query);

System.out.print(" , ");
System.out.print(" , ");

}catch(SQLException e){System.out.println("Exception: " + e);}



Unfortunately, oracle error messages are not as informative as mysql or mssql and I am not able to trouble shoot them easily. I am also not able to see which line of code caused the exception.

Answer Source

Try removing the semi colon from the end of your SQL statement.


static String query = "SELECT emp_id, emp_name, emp_age " +
    "FROM employee"; // no trailing ";" in the SQL
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download