Forum Discussion
Marsha_R
4 years agoChampion Level 3
Here's some information about working with databases:
Yes, you can use variables if you use the correct format.
What have you already tried and what happened when you did?
- Mr_Bro4 years agoChampion Level 0
Please find the below python script to retrieve the data from database and log the count the record set.
import sys sys.path.insert(0,r'c:\users\skuma37\appdata\roaming\python\python38\site-packages') import mysql.connector def SampleDBCheck(): connection = mysql.connector.connect( host="HOSTNAME", database='DATABASENAME', user="USERNAME", password="PASSWORD" ) sql_select_Query = "select * from SampleTable where id < 10" cursor = connection.cursor() cursor.execute(sql_select_Query) records = cursor.fetchall() Log.Message("Total number of rows in table: "+ str(cursor.rowcount))
- rohini114 years agoNew Contributor
Hi Satish,
Thanks for the reply.
I'm beginner in coding and trying to work with Java script.
- Mr_Bro4 years agoChampion Level 0
rohini11 ,
can you please try the below snippet by changing the necessary connecting string and query and tell us what is the error:
function TestProc() { var AConnection, RecSet; AConnection = ADO.CreateADOConnection(); AConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"+ "Data Source=C:\\Users\\Public\\Documents\\TestComplete 14 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb"; AConnection.LoginPrompt = false; AConnection.Open(); // Execute a simple query RecSet = AConnection.Execute_("SELECT * FROM orders WHERE [quant] > 1"); RecSet.MoveFirst(); while(! RecSet.EOF) { //Print the recordset value into the Log Log.Message(RecSet.Fields.Item("name").Value); RecSet.MoveNext(); } AConnection.Close(); }
Related Content
Recent Discussions
- 14 hours agotramuntana
- 3 days agoSlickRick