How to write "select column name as "alias" from table name" in java odbc

676 Views Asked by At
String sql="select ID as \"Batch ID\", NAME as \"Batch Name\",START_DATE as \"Start date\",END_DATE as \"End date\"FROM BATCH order by NAME;";      
try {
    pst = con.prepareStatement(sql);
    rs = pst.executeQuery();
    jTable1.setModel(DbUtils.resultSetToTableModel(rs));
}
catch(Exception e) {
    JOptionPane.showMessageDialog(null, e);
}     

This code returns an error

java.sql.SQLException:ORA-00911:invalid character

I have also tried removing \ from the query and replacing with '. But it didn't work for me

2

There are 2 best solutions below

0
dmitrievanthony On

Semicolon character ; is not a part of statement so you need to remove it.

0
Vadim On
\"End date\"FROM

There is your problem. You forgot a space then it is "End date"FROM. Next time print your statement. Then run it in Oracle directly :)