Reply
New Contributor
Posts: 1
Registered: ‎05-08-2017

Backslash being added to Java Prepared Statement before special characters

Using the below class with JDBC41 driver I'm running a Prepared Statement and passing "speed (km/h)" as parameter. It is being returned as "speed \(km/h\)"

public static void main(String[] args) {
        try {
            String url = "jdbc:impala://[DB_IP]:[PORT]/default;impala_db=true;auth=noSasl;UseNativeQuery=1";
            Connection conn = DriverManager.getConnection(url,"","");
            ResultSet rs;

            String Query = "select '22' as ?";
            PreparedStatement selectQuery = conn.prepareStatement(Query);

            selectQuery.setString(1, args[0]);

            rs = selectQuery.executeQuery();

            ResultSetMetaData rsmd = rs.getMetaData();

            while ( rs.next() ) {
                String s = rs.getString( 1 );
                String name = rsmd.getColumnName(1);
                System.out.println(name + " " + s);
            }
            conn.close();
        } catch (Exception e) {
            System.err.println("Got an exception! ");
            System.err.println(e.getMessage());
        }
    }
Announcements