Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Help! Newbie needs help with simple JDBC calls

Re: Help! Newbie needs help with simple JDBC calls

From: Peter Sylvester <peters_nospam_please_at_mitre.org>
Date: Tue, 06 May 2003 09:27:39 -0400
Message-ID: <b98d8b$han$1@newslocal.mitre.org>


Try building your SQL in a separate String and print it out just before executing. Maybe "id" has a space in front of it or something.

Once working, you should also look at using prepared statements with bind variables for better performance.

Also should have a finally block to close resources (resultsets, statements, connections, etc).

--Peter

Gora Sudindranath wrote:
> Hi,
>
> I'm having problems with the following code:
>
> Question question = new Question();
> Connection con = null;
> Statement stmt = null;
> try
> {
> con = getConnection();
> stmt = con.createStatement();
> ResultSet rs = stmt.executeQuery("SELECT TEXT FROM
> QUESTION WHERE QUESTION_ID = '" + id + "'");
> if(rs.next())
> {
> question.setId(id);
> question.setText(rs.getString(1));
> loadAnswers(question);
> }
> }
> My result set always returns empty, even though I can execute the
> query from toad and it returns one record. Any idea what is going on?
> I'm using the following config:
>
> Tomcat 4.1
> Oracle 8.1.7
> Oracle Thin JDBC Driver
>
> The SQL DDL for the table I am trying to select from is as follows:
>
> CREATE TABLE QUESTION (
> QUESTION_ID VARCHAR2 (10) NOT NULL,
> CATEGORY_ID VARCHAR2 (10) NOT NULL,
> TEXT VARCHAR2 (2000) NOT NULL,
> IS_ACTIVE VARCHAR2 (1) NOT NULL,
> CREATE_DATE DATE,
> CONSTRAINT CK01_QUESTION
> CHECK (IS_ACTIVE IN ('Y', 'N')),
> CONSTRAINT PK_QUESTION
> PRIMARY KEY ( QUESTION_ID )
> USING INDEX
> TABLESPACE USERS PCTFREE 10
> STORAGE ( INITIAL 4096K NEXT 1024K PCTINCREASE 0 ))
> TABLESPACE USERS NOLOGGING
> PCTFREE 10
> PCTUSED 40
> INITRANS 1
> MAXTRANS 255
> STORAGE (
> INITIAL 4194304
> NEXT 1048576
> MINEXTENTS 1
> MAXEXTENTS 4096
> FREELISTS 1 FREELIST GROUPS 1 )
> NOCACHE;
>
> ALTER TABLE QUESTION ADD CONSTRAINT FK01_QUESTION
> FOREIGN KEY (CATEGORY_ID)
> REFERENCES NIKE_BEAUTIFUL.CATEGORY (CATEGORY_ID) ;
>
> Any help would be much appreciated!
>
> Gora
> gora73175_at_yahoo.com
Received on Tue May 06 2003 - 08:27:39 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US