Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 16th, 2013, 03:24 PM
jojofromjory jojofromjory is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 jojofromjory User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 53 sec
Reputation Power: 0
Other Language - [COBOL] Can't execute SQL query

Hello everyone,

I'm new on this forum and I joined because I have a question about COBOL, I'm making a school project and we have to connect to an SQL-based database (I'm using MySQL). My program can connect to the database but it doesn't want to execute the SQL query I entered, although I do exactly the same as they do on multiple websites.

I want to insert a new row into a table called jonathan in the database called jojo. The login is working since I get SQLCODE 0 & SQLSTATE 00000.

This is my code:

Code:
       IDENTIFICATION DIVISION.
       PROGRAM-ID. dbConn.
       
       DATA DIVISION. WORKING-STORAGE SECTION.
       01 name PIC X(5).
       01 idcode PIC 9(2).
       01 city PIC X(200).
       EXEC SQL 
         BEGIN DECLARE SECTION 
       END-EXEC
      * SQLCODE is 0 for success, 100 for no data, -1 for failure 
       01 SQLCODE PIC S9(3).
      * SQLSTATE is a 5 character communication code; 00xxx is success. 
       01 SQLSTATE PIC X(5).    
       01 JdbcString PIC X(255).
       EXEC SQL
         END DECLARE SECTION 
       END-EXEC
       
       PROCEDURE DIVISION.
       MAIN-PARAGRAPH. 
      * Initial code 
       PERFORM DO-CONNECT
       
       DISPLAY "After connecting to the database:"
       
       DISPLAY "SQLCODE= " + SQLCODE. 
       DISPLAY "SQLSTATE= " + SQLSTATE
       
       MOVE "Jonathann" TO name
       MOVE 28 TO idcode
       MOVE "GENT" TO city
       
      * Use the database
       EXEC SQL
          INSERT INTO jonathan (name, idcode, city) 
          VALUES (:name, :idcode, :city)
       END-EXEC
       
       PERFORM DO-DISCONNECT 
       ACCEPT SQLSTATE 
      * Terminate the program 
       GOBACK
       
      * The SQL connect statement must be completed with the information 
      * appropriate to the actual JDBC driver in use. JDBC stands for 
      * Java DataBase Connectivity, and it is the method by which PERCobol 
      * accesses databases and database-like data sources. 
      * 
      * The JDBC driver itself must be included in the Java library path 
      * in order to successfully connect to the database. The JDBC driver 
      * is generally included with the database itself; see the database 
      * documentation for more details. * 
      * When connecting to a datasource, the jdbc:url may be 
      * ds:data-source-name. 
      * 
      * jdbc:url The JDBC url to the database itself
      * com.driver.name This is the classname of the driver 
      * 
       DO-CONNECT.
       
       STRING "jdbc:mysql://localhost:3306/jojo?" 
       DELIMITED BY SIZE 
       "user=root&password=jojo123" 
       DELIMITED BY SIZE 
       INTO JdbcString
       
       EXEC SQL 
          CONNECT 
          TO :JdbcString 
      *    DRIVER "com.microsoft.sqlserver.jdbc.SQLServerDriver"
           DRIVER "com.mysql.jdbc.Driver" 
       END-EXEC.
       .
      * Disconnect from the SQL database connection. This allows the 
      * JDBC driver to free any resources required for the connection.

       DO-DISCONNECT. 
       EXEC SQL 
          DISCONNECT 
       END-EXEC.


Thanks in advance.

Greetings, Jojofromjory

Reply With Quote
  #2  
Old February 16th, 2013, 08:29 PM
OmegaZero OmegaZero is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2007
Posts: 737 OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 1 m 12 sec
Reputation Power: 928
One wonders what type of school assigns projects in COBOL of all things...

Anyways, one thing that jumps out at me is you're not performing any error checking on the INSERT (or the DISCONNECT). The value of SQLSTATE after the insert might help debug the problem.

Some databases connect with autocommit disabled. You may need to execute a commit statement or set autocommit=TRUE before your data will be written to the database.

Have you tried running your insert command from whatever sql shell MySQL uses?

I can't comment as to the correctness of the COBOL code. Hopefully someone with COBOL experience will show up, but that's a bit of a rare language.
Comments on this post
jojofromjory agrees: Thanks for helping me!
__________________
sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

Reply With Quote
  #3  
Old February 17th, 2013, 10:22 AM
jojofromjory jojofromjory is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 jojofromjory User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 53 sec
Reputation Power: 0
Quote:
Originally Posted by OmegaZero
One wonders what type of school assigns projects in COBOL of all things...

Anyways, one thing that jumps out at me is you're not performing any error checking on the INSERT (or the DISCONNECT). The value of SQLSTATE after the insert might help debug the problem.

Some databases connect with autocommit disabled. You may need to execute a commit statement or set autocommit=TRUE before your data will be written to the database.

Have you tried running your insert command from whatever sql shell MySQL uses?

I can't comment as to the correctness of the COBOL code. Hopefully someone with COBOL experience will show up, but that's a bit of a rare language.


Thanks!

I didn't know about the committing part (I'm not really that used to SQL and only have a basic knowledge of COBOL).

I just had to add:

Code:
EXEC SQL
   COMMIT
END-EXEC


I added this right before disconnecting from the SQL server, this way, I suppose every change made during the connection will be applied.

Thank you very much for the quick response, this will be a great help for the college project

Greetings, Jojofromjory

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Other Language - [COBOL] Can't execute SQL query

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap