Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

java - 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();
        try {
            FileInputStream fis = new FileInputStream("Login.properties");
            prop.load(fis);
        } catch (IOException ex) {
            ex.printStackTrace();
        }

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

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

            Statement stmt = con.createStatement();

            ResultSet rs = stmt.executeQuery(query);

            while (rs.next()) {
                System.out.print(rs.getString("emp_id"));
                System.out.print("  ,  ");
                System.out.print(rs.getString("emp_name"));
                System.out.print("  ,  ");
                System.out.print(rs.getString("emp_age"));
                System.out.println();
            }
        } 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

ie

static String query = "SELECT emp_id, emp_name, emp_age " +
    "FROM employee"; // no trailing ";" in the SQL

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...