了解神秘的Oracle JDBC错误 - ORA-00911:无效字符 [英] Understanding mysterious Oracle JDBC errors - ORA-00911: invalid character

查看:294
本文介绍了了解神秘的Oracle JDBC错误 - ORA-00911:无效字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作Java 1.6-JDBC-Oracle 11代码。我创建了一个名为employee的表,其中包含id,name和age。我收到错误 - ORA-00911:无效字符。我该如何解决这个问题?

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 ?

这是我的代码 -

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);
        }

    }

}



<不幸的是,oracle错误消息不像mysql或mssql那样提供信息,我无法轻易解决它们。我也无法看到哪行代码导致异常。

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.

推荐答案

尝试从你的末尾删除分号SQL语句。

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

这篇关于了解神秘的Oracle JDBC错误 - ORA-00911:无效字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆