LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 11-08-2004, 03:53 PM   #1
randomx
Member
 
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?


Code:
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.
System.err.println(ex.getMessage());
  System.err.println(ex.getErrorCode());
  System.err.println(ex.getSQLState());
 }
}
 
Old 11-09-2004, 11:59 AM   #2
csfalcon
Member
 
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

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

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

PreparedStatement ps = conn.prepareStatement(query);

ps.executeUpdate();
 
  


Reply


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 04:28 AM
is there any tool avilable to convert java/sql code into asp.net/sql2000 rddreamz Programming 1 11-08-2004 03:16 PM
Problem executing java programs nro Programming 2 08-28-2004 02:09 AM
Problem executing this piped command: JAVA randomx Programming 1 07-16-2004 08:39 PM
Problem executing. This is not a due to code error :( estranged Linux - Software 2 09-06-2003 12:20 PM


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

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