java / SQL代码,插入postgres

时间:2014-07-15 21:34:19

标签: java sql postgresql

我试图在postgres中将此数据插入到我的表中,但是我收到此错误:     错误:“左”或附近的语法错误 以下是我的插入和以下参数...

public static void Add(int i, int p) throws SQLException{
    String path = p + "/";

    st = "INSERT INTO melvin_ifis_network (link_id, length, area, up_area, elevation, links_drop, longest_channel_length, to_border, left, right, parent_link, travel_time07, layer, ial, ia_connected, h_order, ia_outlet, branch_layer, memory, branch, model) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    state = connection.prepareStatement(st);
    state.setInt(1, i);
    state.setInt(2, 0);
    state.setInt(3, 0);
    state.setInt(4, 0);
    state.setInt(5, 0);
    state.setInt(6, 0);
    state.setInt(7, 0);
    state.setInt(8, 0);
    state.setInt(9, 0);
    state.setInt(10, 0);
    state.setInt(11, p);
    state.setDouble(12, 0.0);
    state.setInt(13, 0);
    state.setBoolean(14, true);
    state.setBoolean(15, true);
    state.setInt(16, 0);
    state.setBoolean(17, false);
    state.setInt(18, 0);
    state.setInt(19, 0);
    state.setInt(20, 0);
    state.setBoolean(21, true);
    state.executeUpdate();
}

2 个答案:

答案 0 :(得分:2)

left(和right)是一个保留字。你需要引用它:"left"

有关标识符规则的更多详细信息,请参阅手册:http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

答案 1 :(得分:1)

您收到该错误原因left, right是保留字。你必须使用" ""left""right"等双重引用{{1}}来逃避它们