Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 获取JDBC上的插入字符串_Sql_Oracle_Jdbc - Fatal编程技术网

Sql 获取JDBC上的插入字符串

Sql 获取JDBC上的插入字符串,sql,oracle,jdbc,Sql,Oracle,Jdbc,我正在尝试编写一个方法,用输入数组作为使用JDBC的列数,从SQL INSERT查询获取到DB的字符串: public String methodtest(String ListofColumns) { String query = "INSERT INTO" + TableName + "(" + ListOfColumns + ")"; try { stmt = con.createStatement(); ResultSet rs =

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

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的建议。

您可以使用以下模式:

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>
    }
}
公共字符串方法测试(数组列表列)
{
试一试{
}
捕获(SQLException sqlEx){
//处理异常
}
捕获(例外情况除外){
//处理其他异常(如有)
}
最后{
}
}

从开始。对于“插入或更新”功能,请查看
MERGE
语句:@MarkMcDowell,您的问题最初没有试图解决它,对于您所做的和不知道的事情没有任何线索,基本上它只是要求提供一个教程,这是离题的。您应该对其进行编辑以显示您拥有的内容。您在回答中这样做(错误),所以我为您编辑了您的问题,现在我们至少有一些代码可以开始。那么现在,问题是什么?