oracle.jdbc.driver.OracleDriver cannot be found by com.parasoft.xtest.libs.base_9.7.7.20180207

VijaysarathyVijaysarathy Posts: 2
edited February 16 in SOAtest

Hi Parasoft team, am getting below error when i try to connect to ora DB, I have included ojdbc6.jar in JDBC driver, DB tool is not surving my purpose so we have to handle this via scripting, can someone help on this please

Additional Details:
oracle.jdbc.driver.OracleDriver cannot be found by com.parasoft.xtest.libs.base_9.7.7.20180207

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver cannot be found by
com.parasoft.xtest.libs.base_9.7.7.20180207
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)

Below is the code snippet for your reference:
from java.sql import DriverManager
from java.lang import Class
from soaptest.api import *
from com.parasoft.api import *

def getValues(input, context):
connection = getConnection()
statement = connection.createStatement()
cspquery = "SELECT * FROM TABLE_NAME WHERE ROWNUM<5"
resultSet = statement.executeQuery(cspquery)
while resultSet.next():
# perform some action with returned data
resultSet.getString("EVENT_NAME")
# resultSet.getInt("DB_COLUMN_NAME2")

def getConnection():
# load drive
driverName = "oracle.jdbc.driver.OracleDriver"
Class.forName(driverName)
DB_URL = "jdbc:oracle:thin:user/[email protected]:XXX:SID"
DB_USER = "user"
DB_PASSWD = "pass"
# get connection to database
SQLUtil.getConnection(driverName, DB_URL, DB_USER, DB_PASSWD)

Tagged:

Comments

  • benken_parasoftbenken_parasoft Posts: 911 ✭✭✭
    edited February 17

    Remove "Class.forName(driverName)". That line is incorrect and superfluous.
    That line would normally load the specified JDBC Driver class using the script's class loader and then register it in the java.sql.DriverManager. However, this will not work because JDBC drivers added to JDBC preferences are accessed with a different class loader than the one used to execute scripts. To be able to access and load classes from the JDBC preferences, you must use methods from com.parasoft.api.SQLUtil which I see you are already doing.

    DB tool is not surving my purpose so we have to handle this via scripting

    Can you be more specific about what this means, what the DB Tool is not able to do for you?

  • VijaysarathyVijaysarathy Posts: 2
    edited February 17

    Thank you so much, it worked, now is that am trying to save the output to a file/databank. Basically, I wanted to fetch the table values on the runtime and add assertions on each the table cols/ value. please let me know if there is a way to do it. i will explore more on it. thanks.

  • benken_parasoftbenken_parasoft Posts: 911 ✭✭✭
    edited February 17

    The DB Tool provides the SQL ResultSet as an XML document. So, you can perform extractions with an XML Data Bank and XML Transformer Tools. You can perform validations with the Diff tool (XML mode) or XML Assertor tools, for example.

    See Validating the Database Layer which links to other relevant sections of the user's guide and tutorial.

Sign In or Register to comment.