I am trying to insert data into a table in SQL server through java. The first is an ID, the second is a nvarchar name, and the third is an xml type (Where I insert it as a string).
I have a db manager class that manages the query execution itself (Including the connection to the DB).
The code for inserting :
stmt = String.format("INSERT INTO [dbo].[WorkflowFull] ([ID], [Name], [Workflow]) VALUES (%d, N'%s', N'%s')", workflowID, fileNameForDB, fileContent);
try{
dbManager.insert(stmt);
} catch (SQLException e){
System.out.println("Problem adding workflow " + fileName + " to DB");
e.printStackTrace();
continue;
}
The error I am getting:
java.sql.SQLException: Wrong number of parameters: expected 3, was given 0 Query: INSERT INTO [dbo].[WorkflowFull] ([ID], [Name], [Workflow]) VALUES (1, N'testWorkflow', N'<Workflow name="NetMonitorTester" start="atomic">
<atomic name="atomic" startingPoint="monitor" hostType="PC" multiplicity="1">
<activity package="MonitorNetwork" name="monitor" input="null" stopCondition="never">
<filter query="regex:GET.+(.{10,})\1{10,}"/>
<resultQuery retrieve="SELECT * FROM PUBLIC.TCP_PACKETS"/>
</activity>
</atomic>
</Workflow>') Parameters: []
at org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:392)
at org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:610)
at org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:516)
at org.bgu.ddms.utils.dbutils.DbManager.insert(DbManager.java:165)
at org.bgu.ddms.cnc.CNC.populateWorkflows(CNC.java:289)
at org.bgu.ddms.cnc.CNC.populateDB(CNC.java:244)
at org.bgu.ddms.cnc.Main.main(Main.java:108)
When I run the exact same query in SSMS, everything works fine