0

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)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    I’m normally fine with your answers about Selenium, but implying as you do 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. This answer should reflect that. – JimEvans Aug 12 '19 at 11:30
  • @JimEvans I am not sure where within the answer I would have incorporated your valuable comments so I added your comment as a **Note** at the end. – undetected Selenium Aug 12 '19 at 11:42
  • @DebanjanB `the standard structure of a pl/sql statement to be executed through Selenium is as follows:` is where he saw it. – JeffC Aug 12 '19 at 13:10
  • 1
    The implication is in this sentence: “However, the standard structure of a pl/sql statement to be executed through Selenium is as follows:” That should be worded differently. – JimEvans Aug 12 '19 at 13:11