Reputation: 103
I am using Marklogic Optic Java API as follows :-
ModifyPlan plan = p.fromView(SchemaName, ViewName)
.where(p.eq(p.col("COL1"), strColValue))
.select(colSeq);
Now I have list of data & I need use "WHERE IN" clause for this query.
select * from table where col in ('val1', 'val2'.....,'valn');
Could anyone please tell me how to do this using marklogic Java API.
Thanks & Regards,
Renuka Patil
Upvotes: 2
Views: 378
Reputation: 27
I see p.xs.stringSeq
is deprecated. The documentation is preferring us to use as below:
{
ModifyPlan plan = p.fromView(SchemaName, ViewName)
.where(p.eq(p.col("COL1"),
p.seq(p.xs.string("val"),p.xs.string("val2"))))
.select(colSeq);
}
I changed from p.xs.stringSeq
to p.seq
Upvotes: -1
Reputation: 958
Probably the easiest way to do that is to just pass in a sequence of strings on the right hand side of the join condition:
ModifyPlan plan = p.fromView(SchemaName, ViewName)
.where(p.eq(p.col("COL1"), p.xs.stringSeq("val1", "val2",...,"valn")))
.select(colSeq);
Upvotes: 3
Reputation: 182
One way to use SQL on Marklogic DB using Java is JDBC.You can perform following steps:
Download JDBC driver from: https://jdbc.postgresql.org/download/postgresql-42.1.4.jar & Reference it in your Java Project.
Setup ODBC server on Marklogic DB as described in : https://docs.marklogic.com/guide/admin/odbc (Remember to select your correct DB in this step & for this example, change Auth type to Basic)
Sample Java code can be as follow:
try {
Connection conn1 = DriverManager.getConnection("jdbc:postgresql://MYHOST:PORT/?preferQueryMode=simple","USER","PWD");
Statement stmt = conn1.createStatement();
String sqlstmt = "select SCHEMA.VIEW.COLUMN1, VSCHEMA.VIEW.COLUMN2, SCHEMA.VIEW.COLUMN3 from SCHEMA.VIEW where SCHEMA.VIEW.COLUMN4 in ('VAL1', 'VAL2', 'VAL3')";
ResultSet rs = stmt.executeQuery(sqlstmt);
while(rs.next()){
String c1= rs.getString("COLUMN1");
String c2= rs.getString("COLUMN2");
System.out.println("COL1:"+c1);
System.out.println("COL2:"+c2);
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
Note:
Hope it helps you :-)
Upvotes: 1