我在scriptlet中有这个代码来连接到Oracle 11g数据库。这位于asp中并将从数据库返回数据(请忽略使用scriptlet并忽略MVC模式,我无法做任何事情)当我尝试连接数据库并运行查询时我收到此错误java.sql.SQLSyntaxErrorException:ORA-00933:SQL命令未正确结束。有人可以查看代码,看看我做错了什么?非常感谢
Driver myDriver = new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(myDriver);
Connection conn = null;
Statement statement = null;
ResultSet resultSet = null;
String DBURL = "jdbc:oracle:thin:@localhost:1521:aaa";
String DBUSER = "user";
String DBPASSWORD = "password";
StringBuffer sql = new StringBuffer();
sql.append("select 'aa', count(*) from queue where priority <= 3 ");
sql.append("union ");
sql.append("select 'bb', count(*) from queue where priority = 4 ");
sql.append("union ");
sql.append("select 'cc', count(*) from ccrqueue ");
sql.append("union ");
sql.append("select 'dd', count(*) from ddqueue ");
sql.append("union ");
sql.append("select 'ee', count(*) from eequeue ");
sql.append("union ");
sql.append("select 'ff', count(*) from ffqueue ");
sql.append("union ");
sql.append("select 'gg', count(*) from ggqueue where id is null ");
sql.append("union ");
sql.append("select 'hh', count(*) from hhqueue" );
sql.append("union" );
sql.append("select 'ii', count(*) from iiqueue" );
sql.append("union" );
sql.append("select 'jj', count(*) from jjqueue where queuetype = ERROR" );
sql.append("union" );
sql.append("select 'kk', count(*) from kkqueue" );
sql.append("order by 2 desc" );
try {
conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD);
statement = conn.createStatement();
resultSet = statement.executeQuery(sql.toString());
out.println(resultSet);
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
答案 0 :(得分:4)
有些行需要空格。例如:
sql.append("union" );
sql.append("select 'ii', count(*) from iiqueue" );
将导致:unionselect 'ii', count(*) from iiqueue
thal将生成ORA-00933