I want to create a Java selinum Web driver script (Maven project)
I want to connect to my Mongo DB (database already exists), execute a query on a collection ({dublinCore.externalID: "123456"}) and get the result.
I try these lines of code but I'm stuck in this step:
#BeforeSuite
public void MongodbConnection()
{
Logger mongoLogger= Logger.getLogger("org.mongodb.driver");
mongoclient= MongoClients.create("");
mongodatabase= mongoclient.getDatabase("db01");
mongodatabase.runCommand()
}
I try to put my database URI in MongoClients.create("");
I try to put the query in mongodatabase.runCommand();
Is that only what I need to execute a query or what? I just want to get the result from the database to make assertion with the current result.
Related
Please give step by step process
How to connect MySQL db and excute queries and stored those results in db table by using jsr223 sampler? Please give sample code this topic
Download MySQL JDBC Driver and drop it to "lib" folder of your JMeter installation (or other folder in JMeter Classpath)
Restart JMeter to pick up the .jar
Add Thread Group to your Test Plan
Add JSR223 Sampler to your Thread Group
Put the following code into "Script" area:
import groovy.sql.Sql
def url = 'jdbc:mysql://your-database-host:your-database-port/your-database-name'
def user = 'your-username'
def password = 'your-password'
def driver = 'com.mysql.cj.jdbc.Driver'
def sql = Sql.newInstance(url, user, password, driver)
def query= 'INSERT INTO your-table-name (your-first-column, your-second-column) VALUES (?,?)'
def params = ['your-first-value', 'your-second-value']
sql.executeInsert query, params
sql.close()
Change your-database-host, your-database-port, etc. to real IP address, port, credentials, table name, column name, etc.
Enjoy.
More information:
Apache Groovy - Working with a relational database
Apache Groovy - Why and How You Should Use It
P.S. I believe using JDBC Request sampler would be way faster and easier
I am using MySQL as my application database, but HSQL as test in-memory database. Now the issue is I have a SQL selectQuery like below :
SELECT date(a.created_at) as record_date
FROM table a
Now, date() is a function in MYSQL for converting DateTime to Date, but in HSQL the same function is to_date(). Now, I have a method which hits the above query to database and gets output.
public Response dbQueryThroughJdbcTemplate(String selectQuery){
jdbcTemplate.query(selectQuery, RowMapper); //RowMapper maps output to Response
}
Now, I have a test method for testing this method,
#Test
public void testDbQueryThroughJdbcTemplate(){
Response response = dbQueryThroughJdbcTemplate(selectQuery);
TestCase.assertEquals(expected, response); // avoided the code for making expected object
}
Now, as the test environment is using HSQL db, the test throws an error that date method is not available.
How to come out of this issue, or any better way to achieve this?
You can try an alternative that is supported by both HSQLDB and MySQL
SELECT CAST(a.created_at AS DATE) as record_date FROM table a
I have a query in Maximo which when run via DB visualizer runs fine. but the same query when I run in java via jdbc it throws sql exception.
The query is a bit different than usual and is shown below.
It gives the next sequence number for the next entry.
select nextval for mytabledseq from sysibm.sysdummy1
I have found the issue. I had to add the schema name before mytableseq.
e.g. MAXIMO.mytableseq now it works fine
I need to create H2 file db on demand(first connection) from backup-ed script.
As I understand it could be done only by using two different urls:
jdbc:h2:file:sampledb;INIT=RUNSCRIPT FROM 'create.sql'; (Should be executed only one time)
jdbc:h2:file:sampledb;IFEXISTS=TRUE;
The problem is that in application connection to db is coming from JNDI so I should set up only one correct url. Does any ability exist to specify parameters based on some condition?
And how to get this conditionn from H2? (Something like jdbc:h2:file:sampledb;!{dbixists}=runscript...). Or some ternary operation is allowed?
I would simply include IF NOT EXIST clauses inside the create.sql script and run it everytime. It would create the DB model only if there is no proper model at all.
I want to know how to run FileMaker(FMP pro) database command in java. I have got the connection to database,but not sure how to execute below query.
Get(AccountPrivilegeSetName)
ref:
http://www.filemaker.com/11help/html/func_ref2.32.4.html#1051898
You will need to add a calculation field in FileMaker to return as the result of the JDBC query. This is because you cannot call functions via JDBC, you can only retrieve field values.