Connect to Oracle SQL in Katalon Studio

I tried using the Groovy script below to connect to an Oracle SQL :

 def connectDB(String dataFile){ //Load driver class for your specific database type Class.forName("oracle.jdbc.driver.OracleDriver") String connectionString = "jdbc:sqlite:" + dataFile if(connection != null && !connection.isClosed()){ connection.close() } connection = DriverManager.getConnection(connectionString) return connection } 

There is sqlite in the connection string, but not sure what value I should use there. (I also tried jdbc:oracle .)

I use the following class to connect to the database.

 public class sqlconnect { private static Connection connection = null; /** * Open and return a connection to database * @param dataFile absolute file path * @return an instance of java.sql.Connection */ @Keyword def connectDB(String dataFile){ //Load driver class for your specific database type Class.forName("oracle.jdbc.driver.OracleDriver") String connectionString = "jdbc:sqlite:" + dataFile if(connection != null && !connection.isClosed()){ connection.close() } connection = DriverManager.getConnection(connectionString) return connection } /** * execute a SQL query on database * @param queryString SQL query string * @return a reference to returned data collection, an instance of java.sql.ResultSet */ @Keyword def executeQuery(String queryString) { Statement stm = connection.createStatement() ResultSet rs = stm.executeQuery(queryString) return rs } @Keyword def closeDatabaseConnection() { if(connection != null && !connection.isClosed()){ connection.close() } connection = null } /** * Execute non-query (usually INSERT/UPDATE/DELETE/COUNT/SUM...) on database * @param queryString a SQL statement * @return single value result of SQL statement */ @Keyword def execute(String queryString) { Statement stm = connection.createStatement() boolean result = stm.execute(queryString) return result } } 

I already installed the database information under Project > Settings > Database in Katalon Studio. I call from testcase using the CustomKeyword connectDB() and executeQuery() methods.

UPDATE:

I updated the connectDB() method of the Groovy script:

 def connectDB(){ Class.forName("oracle.jdbc.driver.OracleDriver") //String connectionString = "jdbc:oracle:thin:username/ password@ipaddress :port/servicename" if(connection != null && !connection.isClosed()){ connection.close() } connection = DriverManager.getConnection("jdbc:oracle:thin:username/ password@ipaddress :port/servicename", "username", "password") return connection } 

I tried to use the connectionString variable as a parameter to the DriverManager.getConnection() method, but in both cases I got the same error message.

Unable to pass object 'oracle.jdbc.driver.T4CConnection @' with class 'oracle.jdbc.driver.T4CConnection' to class 'Com.mysql.jdbc.Connection'

+5
source share
1 answer

The format of the connection string is jdbc:oracle:<drivertype>:@<database> (for example, jdbc:oracle:thin:@host:1521:xe ).

You can pass the user the password to call: DriverManager.getConnection("<connection string>", "<user>", "<password>"); or even in the connection string: jdbc:oracle:<drivertype>:<user>/<password>@<database> (for example, jdbc:oracle:thin:scott/ tiger@host :1521:xe ).

You should learn more about connection strings.

+1
source

Source: https://habr.com/ru/post/1275846/


All Articles