FAILED: dbconnection com.microsoft.sqlserver.jdbc.SQLServerException: Could not find stored procedure while executing SQL query through Selenium

560 views Asked by At

I have made the sql connection , and fetching the query from excel sheet. and after establishing db cooncetion, calling:

result rs= st.executeQuery(query)

statement is showing error as couldnot find storedprocedure.

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String querypath = "C:/Users/svhirekalmath/eclipse-workspace/NepalBITestNg/queries/queries.xlsx"; 
FileInputStream queryFile = new FileInputStream(new File(querypath));
XSSFWorkbook queryBook = new XSSFWorkbook(queryFile);
Sheet querySheet=queryBook.getSheet("Sheet1");

String query=ReusableFunctions.getPropertiesValue("COMPANY"); // fetching query 
queryBook.close(); 

Connection con = DriverManager.getConnection("jdbc:sqlserver://cdtssql879d;database=NepalBI_1","SNABI_user","SNABI@123");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query); // getting error at this line 

Error:

FAILED: dbconnection
com.microsoft.sqlserver.jdbc.SQLServerException: Could not find stored procedure 'applicationPassword'.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1454)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:786)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:685)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:185)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:160)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:620)
    at marketoverview.MarketOverviewTest.dbconnection(MarketOverviewTest.java:153)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
1

There are 1 answers

4
undetected Selenium On

This error message...

FAILED: dbconnection
com.microsoft.sqlserver.jdbc.SQLServerException: Could not find stored procedure 'applicationPassword'.

...implies that there was an error while your program tried to execute the query.

A bit more details about the line:

String query=ReusableFunctions.getPropertiesValue("COMPANY");

would have helped us to analyze the issue in a better way. However, the standard structure of a pl/sql statement to be executed through Selenium is as follows:

String query = "select * from seleniumuser"

So ideally,

String query=ReusableFunctions.getPropertiesValue("COMPANY");
System.out.println(query);

should print something similar to:

select * from seleniumuser

Additionally, the instance of the Connection should have included the port number as follows:

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/selenium","root","root");

The port number seems to be missing from your code trial:

Connection con = DriverManager.getConnection("jdbc:sqlserver://cdtssql879d;database=NepalBI_1","SNABI_user","SNABI@123");

Note: @JimEvans in his comment further clarified that Selenium has any support for executing SQL queries is misleading. It’s standard Java library execution, and has absolutely nothing to do with Selenium