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

Home -> Community -> Usenet -> c.d.o.misc -> Re: insert statment for Oracle ?

Re: insert statment for Oracle ?

From: Mark C. Stock <mcstockX_at_Xenquery>
Date: Sun, 7 Dec 2003 09:53:26 -0500
Message-ID: <OZqdnQkqr_-Mok6i4p2dnA@comcast.com>

"Daniel Morgan" <damorgan_at_x.washington.edu> wrote in message news:1070780006.487012_at_yasure...
| mhk wrote:
|
| > Hi ,
| >
| > i am having problems in inserting record into oracle database i have the
| > following function written for insert but it doesnt work.
| >
| > can anyone check to see whats wrong. it seems ok to me. my connection is
| > also working. i can select records and cannot insert.
| >
| > Thanks
| >
| > MY Insert FUNCTION is as below
| > *********************************************
| >
| > public int create_customer(String v1,String v2, String v3, String v4,
| > String v5, String v6)
| > {
| >
| > int result = 0 ;
| >
| > try {
| >
| > Connection conn =
| >

DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:global2","test ",
| > "test");
| > String sqlst = "insert into customer values
| > ('v1','v2','v3','v4,'v5','v6','v7')";
| >
| > PreparedStatement pst = conn.prepareStatement(sqlst);
| > int v = pst.executeUpdate ();
| > conn.close();
| > pst.close();
| > result = 2 ; // 2 means record added successfully
| > } catch (SQLException e)
| > {
| > System.out.println("There was an error doing the query:");
| > }
| > return result;
| > } // end of method
| >
| >
| > ********************************************************
| >
|
| A little more information would be valuable.
|
| For example are you getting an error message?
|
| But in the end I suspect it is doing the insert just fine.
| But your code does not contain a commit.
|
| --
| Daniel Morgan
| http://www.outreach.washington.edu/ext/certificates/oad/oad_crs.asp
| http://www.outreach.washington.edu/ext/certificates/aoa/aoa_crs.asp
| damorgan_at_x.washington.edu
| (replace 'x' with a 'u' to reply)
|

also might be a problem with not explicitly specifying the columns for the INSERT statement -- if your CUSTOMER table does not have 7 columns (or in the future is altered to have more than 7 columns, or the is rebuilt with columns in a different order), you will get errors. also, you may have a implicit datatype conversion problems -- it's doubtful that all 7 columns in the CUSTOMER table or VARCHAR2

Received on Sun Dec 07 2003 - 08:53:26 CST

Original text of this message

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