Run Database query using Java or .net code

Hi everyone,

I have a scenario and i have struck there from long time. I want to connect my database using JDBC server. Without using UiPath activities.
I want to connect Database and Run Query using JavaScript or .net code or any other codes.
Can anyone help me how I can achieve this.
There is a specific request from business that’s why we are not using UiPath activities

Based on Meta AI

To connect to a database using JDBC in C#, you’ll need to use a JDBC driver specific to your database management system (DBMS). The 64 bit driver is for Windows and Cross-Platform projects in UiPath Studio, the 32 bit driver is for Windows - Legacy projects in UiPath Studio. Here’s a general outline of the steps:

Install the JDBC driver:

  • Download the JDBC driver for your DBMS (e.g., MySQL, PostgreSQL, Oracle).

  • Add the driver to your project references.

Connect to the database:

Adapt the below code based on your credentials and IDE

using System;
using System.Data;

// Import the specific JDBC driver namespace (e.g., MySql.Data, Npgsql, Oracle.ManagedDataAccess)

class DatabaseConnection
{
    public static void Main(string[] args)
    {
        // Replace with your database connection details
        string connectionString = "jdbc:mysql://localhost:3306/mydatabase";
        string username = "myuser";
        string password = "mypassword";

        // Create a new JDBC connection
        using (var connection = new MySqlConnection(connectionString, username, password))
        {
            connection.Open();

            // Execute a query
            using (var command = new MySqlCommand("SELECT * FROM mytable", connection))
            {
                var reader = command.ExecuteReader();

                while (reader.Read())
                {
                    Console.WriteLine($"{reader[0]} {reader[1]}");
                }
            }
        }
    }
}

Note:

  • Replace MySqlConnection and MySqlCommand with the appropriate classes from your JDBC driver.

  • Update the connectionString, username, and password with your database credentials.

This is just a basic example to get you started. You may need to add error handling and other features depending on your specific use case.


Also, you can use other third-part libraries, or you can take a look inside the UiPath.Database.Activities package code and retry to do the same but with your code.

Hi @marian.platonov I’m using VB, windows in UiPath and my database is not SQL. Will it work with the above code

Can you use internet or AI and look for a VB.Net example?

Install the JDBC driver:

  • Download the JDBC driver for your DBMS (e.g., MySQL, PostgreSQL, Oracle).

  • Add the driver to your project references.

Connect to the database and run a query:

Vbnet

Imports System
Imports System.Data

Module DatabaseConnection
    Sub Main()
        ' Replace with your database connection details
        Dim connectionString As String = "jdbc:mysql://localhost:3306/mydatabase"
        Dim username As String = "myuser"
        Dim password As String = "mypassword"

        ' Create a new JDBC connection
        Using connection As New MySqlConnection(connectionString, username, password)
            connection.Open()

            ' Execute a query
            Using command As New MySqlCommand("SELECT * FROM mytable", connection)
                Dim reader As MySqlDataReader = command.ExecuteReader()

                While reader.Read()
                    Console.WriteLine($"{reader(0)} {reader(1)}")
                End While
            End Using
        End Using
    End Sub
End Module

Note:

  • Replace MySqlConnection and MySqlCommand with the appropriate classes from your JDBC driver.

  • Update the connectionString, username, and password with your database credentials.

This is just a basic example to get you started. You may need to add error handling and other features depending on your specific use case.

Some popular JDBC drivers for (link unavailable) are:

  • MySql.Data (for MySQL)

  • Npgsql (for PostgreSQL)

  • Oracle.ManagedDataAccess (for Oracle)

Sure @marian.platonov i will try that