Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 378875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:50:13+00:00 2026-05-12T14:50:13+00:00

I am just learning prolog. I have a task ahead. I have to insert

  • 0

I am just learning prolog. I have a task ahead. I have to insert some data in to a database like mysql or MSSQL using Prolog ODBC INterface. I know there are some example predicates(SWI-PROLOG) like

open_wordnet :-
    odbc_connect('WordNet', _,
                 [ user(jan),
                   password(xxx),
                   alias(wordnet),
                   open(once)
                 ]).

I do not know how to exactly use these predicates and show a working example. Can anyone please tell me how do I exactly use these to insert data into a database like MySSQL or MSSQL from prolog. Can anyone please tell me the exact requirements to achieve the same through ProLOG?

Any help or information would be greatly appreciated.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:50:13+00:00Added an answer on May 12, 2026 at 2:50 pm

    Thank you for you responses @ThomasH and @StarWind Software. I could figure out the solutions using the code sames that you pointed out. Well here is a complete picture. I am sure there are so many people out there who need a clear picture of connection from Prolog to a Database.

    Notes:

    1. You can connect to any database from within swi-prolog. I used Oracle 10g and MySQL 5.
    2. First of all download the ‘SWI-Prolog’ ODBC Interface from here.

    3. There are two main ‘dll’ files in the package ‘ODBCProlog.dll’ and ‘OracleProlog.dll’

      Next, this is the sample code which is same as above one. I Will explain the sections

    MYSQL CONNECTION IN PROLOG

    
    
    :- use_module(oracle).
    go :-
        db_open('mysql5', 'root', 'admin'),    
        db_import('EMP'('EMPID', 'EMPNAME'), emp),
        %%db_flag(show_query, _, off),
    
        db_query(emp(EMPID, EMPNAME), emp(EMPID, EMPNAME)),
        %% Run the query.
        get_result,
        %% Modify the database.
        %%emp_ins(109, 1, 221),
        %%test_del(109, 1, 221),
        %% Commit changes.
        db_transaction(commit),
        db_close.
    
    %% Retrieve all records over backtracking.
    get_result:-
        emp(EMPID, EMPNAME),
        write_ln([EMPID, EMPNAME]),
        fail.
    get_result.
    

    Now the explanation part:

    db_open(‘mysql5’, ‘root’, ‘admin’),

    the first part ‘mysql5’ the dsn name for mysql. If you do nmot have it installed in your system, you can download it from the MySQL website. The next one is username and password.

    db_flag(show_query, _, off),

    prints the SQL statements in the output. commenting it will prevent it from outputting the SQL query.

    db_import(‘EMP'(‘EMPID’, ‘EMPNAME’), emp),

    Here ‘EMP’ is the actual table name in the database and ’emp’ is its alias.
    It is important to create this way otherwise it will not work.

    db_query(emp(EMPID, EMPNAME), emp(EMPID, EMPNAME)),

    next for quering the database the above call ‘db_query’ will take 2 arguments. You can either query two tables using this like a JOIN statement. If you are using just quering one table then it is necessary to give the same query twice as this call expects two arguments.

    Is you need to insert anything in the database uncomment


    emp_ins(109, 1, 221),

    This convention is nothing but you are adding _ins to the alias name which is understood by the prolog that it is an insert call to database.

    similarly


    emp_del(109, 1, 221),

    I guess the rest is self explanatory.

    Now, the next part is if you need to connect to Oracle database then the only statement that changes is :

    
    
    :- use_module(odbc).
    

    The rest is pretty same. One thing you have to remember is that you need to use the oracle INSTANCE name while specifying the database.
    Usually in Oracle 10g the instance name is ‘orcl’ and for Oracle Express edition the convention is :

    'your full computer name:port/XE','username','password'

    You WILL be able to connect to database and display the results with this block of code,

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 290k
  • Answers 290k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It is impossible with XmlSerializer without implementing IXmlSerializable or creating… May 13, 2026 at 5:47 pm
  • Editorial Team
    Editorial Team added an answer You can implement as many custom ConfigurationSections as you'd like.… May 13, 2026 at 5:47 pm
  • Editorial Team
    Editorial Team added an answer If using a standard Silverlight application (not out of browser),… May 13, 2026 at 5:47 pm

Related Questions

Please advise. I am a lawyer, I work in the field of Law Informatics.
I am just learning about app.config in respect of creating custom sections. I have
I am just learning C# through Visual Studio 2008? I was wondering what exactly
I am just learning Ruby and I don't quite understand the difference between several

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.