【问题标题】:Get INSERT string on JDBC在 JDBC 上获取 INSERT 字符串
【发布时间】:2015-03-20 03:21:09
【问题描述】:

我正在尝试编写一个方法来从 SQL INSERT 查询中获取字符串到 DB,使用 JDBC 将输入数组作为列数:

public String methodtest(String ListofColumns)
{
    String query = "INSERT INTO" + TableName + "(" + ListOfColumns + ")";
    try
    {
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        While (rs.next())
        {
            String result = rs.getString(query);
            System.out.println("The SQL query is " + result);
        }
    }
    catch (SQLException sqlEx)
    {
        e.printStackTrace();
    }
    finally
    {
        rs.close();
    }
}

你能看出有什么错误吗?

感谢 Monkawee 的建议。

【问题讨论】:

  • this tutorial开头。
  • 对于“插入或更新”功能,请查看MERGE 声明:docs.oracle.com/cd/E11882_01/server.112/e41084/…
  • @MarkMcDowell,您的问题最初显示没有解决它,不知道您做什么和不知道,基本上它只是要求一个教程,这是题外话。您应该对其进行编辑以显示您拥有的内容。您在回答中(错误地)这样做了,所以我为您编辑了您的问题,现在我们至少有一些代码可以开始。那么现在,问题是什么?

标签: sql oracle jdbc


【解决方案1】:

您可以使用以下模式:

public string methodtest(Array listofcolumns)
{
    try{
        <Connection string path>
        <DB connection method>
        <Query string>
        <Execution>
        <Reset Object>
    }
    catch(SQLException sqlEx){
        // handle exception
    }
    catch(Exception ex){
        // handle other exceptions if any
    }
    finally{
        <Close connection and other resources like PreparedStatement>
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 2017-04-03
    • 2015-07-07
    相关资源
    最近更新 更多