Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-08-2004, 02:53 PM   #1
Registered: Feb 2003
Location: Hawaii
Distribution: Debian
Posts: 130

Rep: Reputation: 16
Unhappy java code executing SQL statements problem

Please enlighten me. This is driving me crazy.

I don't know if this is a database or java code related problem.

JVM: 1.4.2
Database: Oracle 9i

Objective: trying to add a row into a table

Problem: 1. SQL statement never gets executed.
2. Application freezes. I have to terminate it myself.

Any Ideas?

void addCourse(){

try {
    DriverManager.registerDriver ( new oracle.jdbc.driver.OracleDriver () ) ;
   System.out.println("Driver registered");  //---> ok.
Connection conn = DriverManager.getConnection ( dbPath, username, password ) ;
   System.out.println("Connected");   // -----> it connects fine

   ResultSet rset = stmt.getResultSet();
   System.out.println("getting result set");  //-----> gets the resultSet fine

  Statement stmt = conn.createStatement();
  System.out.println("statement created");  //------> it creates statement

7 = are the credits. Number on table. Length allowed 5.
CS 500 = are the course code. Varchar2 on table. Length allowed 20
Java = Actual course name. Varchar2 on table. Length 30
3 = credits. Number on table. Length 5.
          // Prepare a statement to insert a record
          String sql = "INSERT INTO course VALUES (7 , 'CS 500', 'Java', 3 )"; //-->ok. Tested it manually  
          // Execute the insert statement
        stmt.executeUpdate(sql);  //----> *** java program freezes right here.***
        System.out.println("sql executed");   //--> Checked table. SQL never gets executed. 
catch ( SQLException ex ) {   //---> no error messages thrown.
Old 11-09-2004, 10:59 AM   #2
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Rep: Reputation: 31
I usually use prepareStatement(String) instead of createStatement()

String query = "INSERT INTO course VALUES (7 , 'CS 500', 'Java', 3 )"; 

PreparedStatement ps = conn.prepareStatement(query);



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in executing code in gcc gcc_learner Programming 3 03-26-2005 03:28 AM
is there any tool avilable to convert java/sql code into rddreamz Programming 1 11-08-2004 02:16 PM
Problem executing java programs nro Programming 2 08-28-2004 01:09 AM
Problem executing this piped command: JAVA randomx Programming 1 07-16-2004 07:39 PM
Problem executing. This is not a due to code error :( estranged Linux - Software 2 09-06-2003 11:20 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:17 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration