我正在制作 Java 1.6-JDBC-Oracle 11 代码。我创建了一个名为employee 的表,其中包含id、name 和age。我收到错误 - ORA-00911:无效字符。我怎样才能解决这个问题 ?
这是我的代码-
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 信息丰富,我无法轻松解决它们。我也看不到哪行代码导致了异常。