ExecuteUpdate - return ID

My problem: I execute an update to a Database with executeUpdate(). How can I get the ID of the affected row, like it is possible in PHP?

But I think that JDBC is a weak tool. It should have
more methods for daily problems with Databases. For a
large number of simple problems missing methods force
you to write them by yourself (methods from PHP like
stripslashes, addslashes, etc.). Java is strong, but
JDBC is weak, I think.we can very well argue about this but keep this in mind: JDBC is meant as a database access layer that provides the funtionality to handle database tasks. php otoh is build to make it easy and efficient to build dynamic web applications. you just lack a library of the methods you are missing because they are there. but you can't blame jdbc for it.
robert

Similar Messages

  • ExecuteUpdate() returns 1 , but actually it has'nt updated the DB tables

    DATABASE USED : ORACLE 9i
    This is the function that is been called.
    althou, this returns a +ve ans. , saying that the db has been updated ; but when i login into the DB, i donot find the row updated.
    public void process(File dir) throws Exception
         FileInputStream fileIn = null;
         byte b[] = null;
         PreparedStatement stmt = null;
         PreparedStatement stmtBank = null;
         PreparedStatement stmtBrand = null;
         ResultSet rs = null;
         String updateBankInfoTable = "UPDATE ARBANKINFO SET ISSUERLOGO_LARGE = ? WHERE BANKID=?";
         String updateBrandInfoTable = "UPDATE ARBRANDINFO SET ISSUERLOGO_LARGE = ? WHERE BANKID=? and RANGEID = ?";
         int bankId = 0;
         int rangeId = 0;
         // FileNotFoundException or SecurityException might
         // be thrown while reading the files in this dir.
         try{
         fileIn = new FileInputStream(dir);
         }catch(Exception e)
              e.printStackTrace(p);
         String fileNameStr = dir.getName();
         if (fileNameStr!=null || fileNameStr.length()>0)
              // Read the file in a byte array
              long fileLen = dir.length();
              int readBytes = 0;
         int totalRead = 0;
         b = new byte[(int)fileLen];
         while((long)totalRead < fileLen)
         try {
                        readBytes = fileIn.read(b, 0, (int)fileLen);
                   } catch (IOException e1) {
                        e1.printStackTrace(p);
         totalRead += readBytes;
         if (fileIn != null)
         fileIn.close();
         try{
         if (bankIDString!=null)
              stmt = conn.prepareStatement("select BANKID,RANGEID from ARESENROLLPROCESS where MAINLOGOURL = ?" +
                   "and BANKID IN ("+bankIDString+")");
         else
              stmt = conn.prepareStatement("select BANKID,RANGEID from ARESENROLLPROCESS where MAINLOGOURL = ?");
         stmt.setString(1,fileNameStr);
         rs = stmt.executeQuery();
         int i =1;
         while (rs.next())
              bankId = rs.getInt("BANKID");
                   rangeId = rs.getInt("RANGEID");
                   i++;
                   if (rangeId!=0)
                        stmtBrand = conn.prepareStatement(updateBrandInfoTable);
                        stmtBrand.setBytes(1,b);
                        stmtBrand.setInt(2,bankId);
                        stmtBrand.setInt(3,rangeId);
                        if (stmtBrand.executeUpdate()==1)
                                                 p.println("Updated ARBRANDINFO table ");
                        else
                             // log in something
                                                 p.println("*** Column not found in ARBRANDINFO table");
                   else if (rangeId == 0)
                        stmtBank = conn.prepareStatement(updateBankInfoTable);
                        stmtBank.setBytes(1,b);
                        stmtBank.setInt(2,bankId);
                        if (stmtBank.executeUpdate()==1)
                                                 p.println("Updated ARBANKINFO table");
                        else
                                                 p.println("*** Column not found in ARBANKINFO table : " +
                                       "BANKID--> "+bankId);
                   if (stmtBank != null)
                   stmtBank.close();
              if (stmtBrand != null)
                   stmtBrand.close();
         }catch(Exception e)
              e.printStackTrace(p);
         if (stmt != null)
              stmt.close();
         if (stmtBank != null)
              stmtBank.close();
         if (stmtBrand != null)
              stmtBrand.close();
    Any suggestions ?????

    i don't see how not setting the autoCommit parameter
    has anything to do with this.If autocommit is false then an update will not be committed without an explicit commit()!
    >
    I would like to add one more thing in here, which m
    sorry i shud hav added; this particluar fn. does
    update a lot of row; but for some records, althou it
    does say that it has updated(java API ); but in
    reality it does not do it.
    That makes a lot fo difference! It does mean that it is probably not a commit problem but without this extra information my money was on a commit problem. Are you swallowing an exception without reporting it?

  • Code using PreparedStatement.executeUpdate failing in stress test

    Hello,
    I've just recently learned how to use J-Meter and have been performing tests on my programs. One of which performs the following:
    1. Read user data using a simple SELECT password FROM users where userid = 'xxx'
    2. When authenticated, runs an immediate update using value binding via PreparedStatement.executeUpdate() which is really just updating the lastlogin column of the same table with the current date.
    My application servlet is running on Glassfish and uses a jdbc connection pool defined on it. The problem is that at about 200 concurrent executions per second of the process described above, PreparedStatement.executeUpdate() returns 0 instead of 1 at around 20% of the time. The Glassfish server is on a Sunfire X2100 platform running solaris 10 and has 2 gb ram, while the database on the other end is a Oracle 10G R2 on a PC clone Pentium 4 with 512mb ram also running on Solaris 10.
    This failure rate is too high so what can I do to reduce it?
    Thanks in advance,
    - Owen

    Owen_Ilagan wrote:
    Hello,
    200 per second? That's a pretty decent load. Well, I was told that that was the acceptable load for the same app running on a standard pentium 4 machine I don't see how you can talk about "acceptable load" for a given piece of hardware without taking into consideration what the application is doing. A read-mostly web app will be very different from one that's transaction and/or computation intensive.
    so I would like to get better performance from this Sunfire X2100. Unless of course that figure is wrong... I've just recently started learning to scale my java applications and figuring out how to fine-tune the servers my programs would be running on. I think this is a good article:
    http://www.javaworld.com/javaworld/jw-06-2006/jw-0619-tuning.html?page=1
    I don't know where that setting is on Glassfish so its on default. Is there an optimal setting for it? I run JMeter on a different machine. Good - your clients aren't competing for memory with the server that way.
    Again, I dont seem to recall seeing a setting like that on Glassfish. The current pool setting is at Initial size 8, maximimum size of 32. I already tried increasing it to 200+ but there was no noticeable improvement so I set it back to 32. That's sufficient. You don't need 1 connection per user because of the pool. I use 5:1 as a rule of thumb.
    Threads in my worker pool? Hmmm, let me just clarify that I'm running a rather simple web servlet application using the 1.5 SDK and its not a full-blown EE application. Doesn't matter. There is one thread per incoming request. If the worker thread pool is exhausted the requests are queued up. There's an optimal setting for that, too.
    Well, I dont run into any SQL errors so there is no stack trace to log. Huh? You mean your PreparedStatement can return 0 and not have an exception?
    What happens if you try to UPDATE a user record that isn't in the database? Is that possible?
    When PreparedStatement.executeUpdate() is called, it returns 0 instead of 1. I did put the call inside a try-catch to handle java.sql.SQLExceptions but its not throwing one.Interesting. See question above.
    I hope so.Difficult, but you sound like you're doing a rigorous job.
    %

  • The ResultSet.next() returns false....

    Hai,
    I am working on jdbc. The connection credentials all correct, and its getting connected to the sybase without any problems. But I am not able to perform any 'select' or "update" statements...There are no exception or any errors...But the ResultSet.next() returns false and executeUpdate returns 0 . .
    I think you can help me.....Thanks...

    Yes the query is sameAs already pointed out, there are ONLY two possibilities.
    1. The query is not the same
    2. The database is not the same.
    You are making assumptions about what is going on and then drawing conclusions.
    You need to understand that you assumptions are wrong. So it doesn't matter what conclusion you draw.
    In terms of why the query isn't the same there could be any number of reasons but usually it is because you are passing in data and that data isn't what you think (assume) it is. It can also be that you are constructing the SQL and that construction is different. It could be that the environment that you use to test as settings which impact SQL.

  • Need help to handle java FX stuffs...........??

    i am very much new to Java FX i want to do a login acceptance and rejection operation.like ::
    client will click on the button it will open up the window of created by java FX which will give the login screen*(in this case i would like to mention one thing i all ready have a page like usercheck.jsp which is checking if the user is already loged in or not so need to call this JAVA FX window from that page.)*.This java FX window should have a text field and a password field to match with database.it will show a progressber while it is matching the user name password with database.If the login is correct it will give the user the session stuff and allow him to access**(ie.it will be forworded to the page say,cart.jsp)** otherwise it will give a alert message "login faild".any idea about it..............what should i do now???my database is in access and it connected to my program by DA.java.please guide me what should i do,step by step?and consulting with [http://jfx.wikia.com/wiki/SwingComponents]
    now guide me.............
    i have just created a swing button say "click me to login" on a UNDECORATED window............so what next.........
    Edited by: coolsayan.2009 on May 7, 2009 3:35 PM

    my DA.java is like::
    package shop;
    import java.sql.*;
    public class DAClass {
         private static Connection conn;
         private static ResultSet rs;
         private static PreparedStatement ps;
         public static void connect(String dsn, String un, String pwd) {
              try {
                   //access
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   conn=DriverManager.getConnection("jdbc:odbc:"+dsn,un,pwd);
              catch(Exception e) {
         public static boolean chkPwd(String un, String pwd) {
              try {
                   boolean b=false;
                   ps=conn.prepareStatement("select * from cust_info where cust_name=? and cust_pwd=?");               
                   ps.setString(1,un);
                   ps.setString(2,pwd);
                   rs=ps.executeQuery();
                   while(rs.next()) {
                        b=true;
                   return b;
              catch(Exception e) {
                   return false;
         public static ResultSet getCat(){
              try {
                   ps=conn.prepareStatement("select * from item_category where cat_parent=0 order by cat_name");               
                   rs=ps.executeQuery();
                   return rs;
              catch(Exception e) {
                   return null;
         public static ResultSet getSubCat(int cat_id){
              try {
                   ps=conn.prepareStatement("select * from item_category where cat_parent=? order by cat_name");               
                   ps.setInt(1,cat_id);
                   rs=ps.executeQuery();
                   return rs;
              catch(Exception e) {
                   return null;
         public static ResultSet getItems(int cat_id){
              try {
                   ps=conn.prepareStatement("select * from item_info where cat_id=? order by title");               
                   ps.setInt(1,cat_id);
                   rs=ps.executeQuery();
                   return rs;
              catch(Exception e) {
                   return null;
         public static boolean insertOd(int order_id,String cust_id, String dt, String st, double amt,String pro)
              try{
                   ps=conn.prepareStatement("insert into cust_order values (?,?,?,?,?,?)");
                   ps.setInt(1,order_id);
                   ps.setString(2,cust_id);
                   ps.setString(3,dt);
                   ps.setString(4,st);
                   ps.setDouble(5,amt);
                   ps.setString(6,pro);
                   ps.executeUpdate();
                   return true;
                   catch(Exception e)
                        return false;
         public static boolean draft_det(int order_id,String bank_name,String draft_no,String draft_date,String branch,double amount)
              try{
                   ps=conn.prepareStatement("insert into draft_det values (?,?,?,?,?,?)");
                   ps.setInt(1,order_id);
                   ps.setString(2,bank_name);
                   ps.setString(3,draft_no);
                   ps.setString(4,draft_date);
                   ps.setString(5,branch);
                  ps.setDouble(6,amount);
                   ps.executeUpdate();
                   return true;
                   catch(Exception e)
                        return false;
         public static int getOrderId()
              try{
                   int id=0;
                   ps=conn.prepareStatement("select Max(order_id) from cust_order");
                   rs=ps.executeQuery();
                   while(rs.next()){
                        id= rs.getInt(1);
                   return id;
              catch(Exception e)
                   return 0;
    public static boolean credit_det(int order_id,String credit_no,String credit_type,String pin_no)
              try{
                   ps=conn.prepareStatement("insert into credit_det values (?,?,?,?)");
                   ps.setInt(1,order_id);
                   ps.setString(2,credit_no);
                   ps.setString(3,credit_type);
                   ps.setString(4,pin_no);
                   ps.executeUpdate();
                   return true;
                   catch(Exception e)
                        return false;
         public static boolean detailOrder(int order_id,int item_id,int item_number,double item_price)
              try{
                   ps=conn.prepareStatement("insert into order_det values (?,?,?,?)");
                   ps.setInt(1,order_id);
                   ps.setInt(2,item_id);
                   ps.setInt(3,item_number);
                   ps.setDouble(4,item_price);
                   ps.executeUpdate();
                   return true;
                   catch(Exception e)
                        return false;
         public static UserInfo getUserDet(String un) {
              try {
                   ps=conn.prepareStatement("select * from cust_info where cust_name=?");
                   ps.setString(1,un);
                   rs=ps.executeQuery();
                   UserInfo user=null;
                   while(rs.next()) {
                        String uname=rs.getString(1);
                        String pass=rs.getString(2);
                        String fname=rs.getString(3);
                        String lname=rs.getString(4);
                        String addr=rs.getString(5);
                        String city=rs.getString(6);
                        String state=rs.getString(7);
                        String country=rs.getString(8);
                        String contact=rs.getString(9);
                        String question=rs.getString(10);
                        String answer=rs.getString(11);
                        String email=rs.getString(12);
                        String mobile=rs.getString(13);
                        user=new UserInfo(0,fname,lname,addr,city,state,country,contact,question,answer,email,mobile,uname,pass);
                        return user;
              catch(Exception e) {
                   return null;
         public static boolean userInsert(String fname,String lname,String addr,String city,String state,String country,String contact,String question,String answer,String email,String mobile,String uname,String pass ){
              try{
                   ps=conn.prepareStatement("insert into cust_info  values (?,?,?,?,?,?,?,?,?,?,?,?,?)");
                   ps.setString(1,uname);
                   ps.setString(2,pass);
                   ps.setString(3,fname);
                   ps.setString(4,lname);
                   ps.setString(5,addr);
                   ps.setString(6,city);
                   ps.setString(7,state);
                   ps.setString(8,country);
                   ps.setString(9,contact);
                   ps.setString(10,question);
                   ps.setString(11,answer);
                   ps.setString(12,email);     
                   ps.setString(13,mobile);
                   ps.executeUpdate();     
                   return true;               
              catch(Exception e)
                   return false;
         public static boolean chackuname(String un) {
              try {
                   boolean b=false;
                   ps=conn.prepareStatement("select * from cust_info where cust_name=?");
                   ps.setString(1,un);
                   rs=ps.executeQuery();
                   while(rs.next()) {
                        b=true;
                   return b;               
              catch(Exception e) {
                   return false;
         public static boolean adminChk(String un,String pass){
         try{
              boolean b=false;
              ps=conn.prepareStatement("select * from admin where username=? and password=?");
                   ps.setString(1,un);
                   ps.setString(2,pass);
                   rs=ps.executeQuery();
                   while(rs.next())
                        b=true;
                   return b;
         catch(Exception e){
              return false;
         public static String getStatus(int cust_id)
              try{
                   String status=null;
                   ps=conn.prepareStatement("select order_status from cust_order where cust_id=?");
                   ps.setInt(1,cust_id);
                   rs=ps.executeQuery();
                   while(rs.next()){
                        status= rs.getString(1);
                   return status;
              catch(Exception e)
                   return null;
         public static boolean chkCatagory(String cat)
              boolean b=false;
              try{
                   ps=conn.prepareStatement("select * from item_category where cat_name=? ");
                   ps.setString(1,cat);
                   rs=ps.executeQuery();
                   while(rs.next())
                        b=true;
                   return b;     
              catch(Exception e)
                   return false;
         public static int getMaxCatId(){
              try{
                   int id=0;
                   ps=conn.prepareStatement("select MAX(cat_id) from item_category");
                   rs=ps.executeQuery();
                   while(rs.next())
                        id=rs.getInt(1);
                   return id;     
              catch(Exception e)
                   return -1;
         public static boolean catInsert(int catId, String cat, int par)
              boolean flag=false;
              try{
                        ps=conn.prepareStatement("insert into item_category values(?,?,?)");
                        ps.setInt(1,catId);
                        ps.setString(2,cat);
                        ps.setInt(3,par);
                        ps.executeUpdate();
                        flag=true;
                        return flag;
              catch(Exception e)
                   return false;

  • [Solved] 27.8.4 How to Create a VO on a REF CURSOR - Missing first row

    Searching the forum I found: BC4J - Get one less row from view object.
    Dive into BC4J related  --REF CURSOR (Resultset)
    The first message did not have any answers, and the second had a follow up question - still no answers though - and I thought I would try a different title.
    (This is off topic, but it would be a great help if the search results also displayed the number of replys in the thread. That way, I wouldn't have to view the messages that don't have responses.)
    (This will be deployed on a server that has the ADF for JDeveloper 10.1.2 installed, so using that version of JDeveloper to develop the app.)
    Okay, back to the problem ==>
    I created a VO from a ref cursor, using the manual as a guide. When I run a page that displays a read only table of the view object, I am missing the first row. (Always the first row!) I don't have any order set, and if I call the ref cursor in a Java program for testing, I see all rows and the count is correct.
    One other point, when I call the page, I get the following validation error:
    Validation Error
    You must correct the following error(s) before proceeding:
    * JBO-29000: Unexpected exception caught: java.lang.ClassCastException, msg=null
    * null
    I still see the table, it is just missing the first row of data.
    In my form I have first, previous set, next set , and last
    navigation buttons. If I press last then first, the error goes away. I still don't see the missing row though.
    Any guidance would be appreciated! I can post my code, but it is pretty much the same code in the AdvancedViewObjectExamples.zip in the ViewObjectOnRefCursor example. I just substituted my two package calls (getRefCursor and getRefCursorCount).
    Thanks, Ken

    Went back to a backup copy of the source. Fixed the error. Now I'm back to just not being able to see the first row of data.
    Additional Note: I had removed fields in the display. Once I truncated the ps_txn table in the schema defined by the model, the data would display (Still without the first record.)
    Are there any examples that are more in depth than the few pages in the developer guide?
    Here is the code for my VOImpl class:
    package newslinearchive.model.datamodel;
    import java.math.BigDecimal;
    import java.sql.CallableStatement;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Timestamp;
    import java.sql.Types;
    import oracle.jbo.InvalidParamException;
    import oracle.jbo.JboException;
    import oracle.jbo.domain.Date;
    import oracle.jbo.domain.Number;
    import oracle.jbo.server.DBTransaction;
    import oracle.jbo.server.QueryCollection;
    import oracle.jbo.server.SQLBuilder;
    import oracle.jbo.server.ViewObjectImpl;
    import oracle.jbo.server.ViewRowImpl;
    import oracle.jbo.server.ViewRowSetImpl;
    import oracle.jdbc.driver.OracleCallableStatement;
    import oracle.jdbc.driver.OracleTypes;
    // --- File generated by Oracle ADF Business Components Design Time.
    // --- Custom code may be added to this class.
    // --- Warning: Do not modify method signatures of generated methods.
    public class SearchRefCursorImpl extends ViewObjectImpl {
    * This is the default constructor (do not remove)
    public SearchRefCursorImpl() {
    * Overridden framework method.
    * Executed when the framework needs to issue the database query for
    * the query collection based on this view object. One view object
    * can produce many related result sets, each potentially the result
    * of different bind variable values. If the rowset in query is involved
    * in a framework-coordinated master/detail viewlink, then the params array
    * will contain one or more framework-supplied bind parameters. If there
    * are any user-supplied bind parameter values, they will PRECEED the
    * framework-supplied bind variable values in the params array, and the
    * number of user parameters will be indicated by the value of the
    * numUserParams argument.
    protected void executeQueryForCollection(Object qc,Object[] params,int numUserParams) {
    storeNewResultSet(qc,retrieveRefCursor(qc,params));
    super.executeQueryForCollection(qc, params, numUserParams);
    * Overridden framework method.
    * Wipe out all traces of a built-in query for this VO
    protected void create() {
    getViewDef().setQuery(null);
    getViewDef().setSelectClause(null);
    setQuery(null);
    * Overridden framework method.
    * The role of this method is to "fetch", populate, and return a single row
    * from the datasource by calling createNewRowForCollection() and populating
    * its attributes using populateAttributeForRow().
    protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet rs) {
    * We ignore the JDBC ResultSet passed by the framework (null anyway) and
    * use the resultset that we've stored in the query-collection-private
    * user data storage
    rs = getResultSet(qc);
    * Create a new row to populate
    ViewRowImpl r = createNewRowForCollection(qc);
    try {
    * Populate new row by attribute slot number for current row in Result Set
    // populateAttributeForRow(r,0, rs.getLong(1));
    // populateAttributeForRow(r,1, rs.getString(2));
    // populateAttributeForRow(r,2, rs.getString(3));
    // MASTERID NOT NULL NUMBER
    populateAttributeForRow(r,0, rs.getBigDecimal(1));
    //ID NOT NULL NUMBER
    populateAttributeForRow(r,1, rs.getBigDecimal(2));
    // CAID NOT NULL NUMBER
    populateAttributeForRow(r,2, rs.getBigDecimal(3));
    // LANGUAGE NOT NULL VARCHAR2(30)
    populateAttributeForRow(r,3, rs.getString(4));
    // IS_CURRENT_VERSION NOT NULL NUMBER(1)
    populateAttributeForRow(r,4, rs.getBigDecimal(5));
    // FOLDER_ID NOT NULL NUMBER
    populateAttributeForRow(r,5, rs.getBigDecimal(6));
    // FOLDER_REGION_ID NOT NULL NUMBER
    populateAttributeForRow(r,6, rs.getBigDecimal(7));
    // NAME NOT NULL VARCHAR2(256)
    populateAttributeForRow(r,7, rs.getString(8));
    // DISPLAY_NAME VARCHAR2(256)
    populateAttributeForRow(r,8, rs.getString(9));
    // ITEMTYPE NOT NULL VARCHAR2(30)
    populateAttributeForRow(r,9, rs.getString(10));
    // SUBTYPE VARCHAR2(40)
    populateAttributeForRow(r,10, rs.getString(11));
    // SUBTYPE_CAID NUMBER
    populateAttributeForRow(r,11, rs.getBigDecimal(12));
    // PARENT_ITEM_ID NUMBER
    populateAttributeForRow(r,12, rs.getBigDecimal(13));
    // CATEGORY_ID NUMBER
    populateAttributeForRow(r,13, rs.getBigDecimal(14));
    // CATEGORY_CAID NUMBER
    populateAttributeForRow(r,14, rs.getBigDecimal(15));
    // AUTHOR VARCHAR2(50)
    populateAttributeForRow(r,15, rs.getString(16));
    // DESCRIPTION VARCHAR2(2000)
    populateAttributeForRow(r,16, rs.getString(17));
    // PUBLISH_DATE NOT NULL DATE
    populateAttributeForRow(r,17, rs.getDate(18));
    // EXPIREMODE VARCHAR2(90)
    populateAttributeForRow(r,18, rs.getString(19));
    // EXPIRENUMBER NUMBER
    populateAttributeForRow(r,19, rs.getBigDecimal(20));
    // EXPIREDATE DATE
    populateAttributeForRow(r,20, rs.getDate(21));
    // IMAGE VARCHAR2(350)
    populateAttributeForRow(r,21, rs.getString(22));
    // KEYWORDS VARCHAR2(2000)
    populateAttributeForRow(r,22, rs.getString(23));
    // URL VARCHAR2(4000)
    populateAttributeForRow(r,23, rs.getString(24));
    // FILENAME VARCHAR2(350)
    populateAttributeForRow(r,24, rs.getString(25));
    // TEXT CLOB()
    populateAttributeForRow(r,25, rs.getClob(26));
    // FOLDER_LINK_ID NUMBER
    populateAttributeForRow(r,26, rs.getBigDecimal(27));
    // FOLDER_LINK_CAID NUMBER
    populateAttributeForRow(r,27, rs.getBigDecimal(28));
    // ACTIVE NOT NULL NUMBER(1)
    populateAttributeForRow(r,28, rs.getBigDecimal(29));
    // CAN_BE_CHECKEDOUT NUMBER(1)
    populateAttributeForRow(r,29, rs.getBigDecimal(30));
    // IS_ITEM_CHECKEDOUT NUMBER(1)
    populateAttributeForRow(r,30, rs.getBigDecimal(31));
    // CHECKER_USERNAME VARCHAR2(256)
    populateAttributeForRow(r,31, rs.getString(32));
    // CHECKOUT_DATE DATE
    populateAttributeForRow(r,32, rs.getDate(33));
    // FULLSCREEN NOT NULL NUMBER(1)
    populateAttributeForRow(r,33, rs.getBigDecimal(34));
    // INPLACE NOT NULL NUMBER(1)
    populateAttributeForRow(r,34, rs.getBigDecimal(35));
    // CREATEDATE NOT NULL DATE
    populateAttributeForRow(r,35, rs.getDate(36));
    // CREATOR NOT NULL VARCHAR2(256)
    populateAttributeForRow(r,36, rs.getString(37));
    // UPDATEDATE DATE
    populateAttributeForRow(r,37, rs.getDate(38));
    // UPDATOR VARCHAR2(256)
    populateAttributeForRow(r,38, rs.getString(39));
    // SECURITY VARCHAR2(25)
    populateAttributeForRow(r,39, rs.getString(40));
    // VISIBLE NOT NULL NUMBER(1)
    populateAttributeForRow(r,40, rs.getBigDecimal(41));
    // SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,41, rs.getBigDecimal(42));
    // CATEGORY_SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,42, rs.getBigDecimal(43));
    // AUTHOR_SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,43, rs.getBigDecimal(44));
    // CREATE_DATE_SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,44, rs.getBigDecimal(45));
    // ITEMTYPE_SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,45, rs.getBigDecimal(46));
    catch (SQLException s) {
    throw new JboException(s);
    return r;
    * Overridden framework method.
    * Return true if the datasource has at least one more record to fetch.
    protected boolean hasNextForCollection(Object qc) {
    ResultSet rs = getResultSet(qc);
    boolean nextOne = false;
    try {
    nextOne = rs.next();
    * When were at the end of the result set, mark the query collection
    * as "FetchComplete".
    if (!nextOne) {
    setFetchCompleteForCollection(qc, true);
    * Close the result set, we're done with it
    rs.close();
    catch (SQLException s) {
    throw new JboException(s);
    return nextOne;
    * Overridden framework method.
    * The framework gives us a chance to clean up any resources related
    * to the datasource when a query collection is done being used.
    protected void releaseUserDataForCollection(Object qc, Object rs) {
    * Ignore the ResultSet passed in since we've created our own.
    * Fetch the ResultSet from the User-Data context instead
    ResultSet userDataRS = getResultSet(qc);
    if (userDataRS != null) {
    try {
    userDataRS.close();
    catch (SQLException s) {
    /* Ignore */
    super.releaseUserDataForCollection(qc, rs);
    * Overridden framework method
    * Return the number of rows that would be returned by executing
    * the query implied by the datasource. This gives the developer a
    * chance to perform a fast count of the rows that would be retrieved
    * if all rows were fetched from the database. In the default implementation
    * the framework will perform a SELECT COUNT(*) FROM (...) wrapper query
    * to let the database return the count. This count might only be an estimate
    * depending on how resource-intensive it would be to actually count the rows.
    public long getQueryHitCount(ViewRowSetImpl viewRowSet) {
    Long result = (Long)callStoredFunction(NUMBER,
    "PORTAL.SEARCH_REFCURSOR.getRefCursorCount",
    viewRowSet.getParameters(true));
    return result.longValue();
    // ------------- PRIVATE METHODS ----------------
    * Return a JDBC ResultSet representing the REF CURSOR return
    * value from our stored package function.
    * new Object[]{getNamedBindParamValue("Email",params)}
    private ResultSet retrieveRefCursor(Object qc, Object[] params) {
    ResultSet rs = (ResultSet)callStoredFunction(OracleTypes.CURSOR,
    "PORTAL.SEARCH_REFCURSOR.getRefCursor",
    null);
    return rs ;
    private Object getNamedBindParamValue(String varName, Object[] params) {
    Object result = null;
    if (getBindingStyle() == SQLBuilder.BINDING_STYLE_ORACLE_NAME) {
    if (params != null) {
    for (Object param : params) {
    Object[] nameValue = (Object[])param;
    String name = (String)nameValue[0];
    if (name.equals(varName)) {
    return (String)nameValue[1];
    throw new JboException("No bind variable named '"+varName+"'");
    * Store a new result set in the query-collection-private user-data context
    private void storeNewResultSet(Object qc, ResultSet rs) {
    ResultSet existingRs = getResultSet(qc);
    // If this query collection is getting reused, close out any previous rowset
    if (existingRs != null) {
    try {existingRs.close();} catch (SQLException s) {}
    setUserDataForCollection(qc,rs);
    hasNextForCollection(qc); // Prime the pump with the first row.
    * Retrieve the result set wrapper from the query-collection user-data
    private ResultSet getResultSet(Object qc) {
    return (ResultSet)getUserDataForCollection(qc);
    * Return either null or a new oracle.jbo.domain.Date
    private static Date nullOrNewDate(Timestamp t) {
    return t != null ? new Date(t) : null;
    * Return either null or a new oracle.jbo.domain.Number
    private static Number nullOrNewNumber(BigDecimal b) {
    try {
    return b != null ? new Number(b) : null;
    catch (SQLException s) { }
    return null;
    //----------------[ Begin Helper Code ]------------------------------
    public static int NUMBER = Types.NUMERIC;
    public static int DATE = Types.DATE;
    public static int VARCHAR2 = Types.VARCHAR;
    public static int CLOB = Types.CLOB;
    * Simplifies calling a stored function with bind variables
    * You can use the NUMBER, DATE, and VARCHAR2 constants in this
    * class to indicate the function return type for these three common types,
    * otherwise use one of the JDBC types in the java.sql.Types class.
    * NOTE: If you want to invoke a stored procedure without any bind variables
    * ==== then you can just use the basic getDBTransaction().executeCommand()
    * @param sqlReturnType JDBC datatype constant of function return value
    * @param stmt stored function statement
    * @param bindVars Object array of parameters
    * @return function return value as an Object
    protected Object callStoredFunction(int sqlReturnType, String stmt,
    Object[] bindVars) {
    CallableStatement st = null;
    try {
    st = getDBTransaction().createCallableStatement("begin ? := " + stmt +
    "; end;", 0);
    st.registerOutParameter(1, sqlReturnType);
    if (bindVars != null) {
    for (int z = 0; z < bindVars.length; z++) {
    st.setObject(z + 2, bindVars[z]);
    st.executeUpdate();
    return st.getObject(1);
    catch (SQLException e) {
    throw new JboException(e);
    finally {
    if (st != null) {
    try {
    st.close();
    catch (SQLException e) {}
    /**Gets the bind variable value for Email
    public String getEmail() {
    return (String)getNamedWhereClauseParam("Email");
    /**Sets <code>value</code> for bind variable Email
    public void setEmail(String value) {
    setNamedWhereClauseParam("Email", value);
    /**getEstimatedRowCount - overridden for custom java data source support.
    public long getEstimatedRowCount() {
    long value = super.getEstimatedRowCount();
    return value;
    Thanks, Ken

  • Maximum Open Cursors Exceeded - Oracle & Java

    I am using NetBeans ( Forte 5) for developing an application with Oracle Database. My application makes use of executeUpdate, executeQuery statements inorder to access Database.
    After few insertions and deletions of data through the host language( Java), my application stops working. It gives out the error.
    java.sql.SQLException: ORA-01000: maximum open cursors exceeded[/b
    Is this the problem with Forte or Oracle. I am using Oracle in a network in which i have got a tablespace in the Database server.
    How to tackle this problem.

    I am using 3 methods preparedStatements
    1. execute - returns boolean
    2. executeQuery - returns ResultSet
    3. executeUpdate - returns int
    I am closing the ResultSet object returned by executeQuery using
    close() method.
    Is this the correct way to close the open cursor.
    I access the table attributes using a rs.getString(colNum) and
    rs.getInt(colNum)
    Even then i am getting the maximum open cursors exceeded message.
    Will Oracle open a cursor for execute and executeUpdate which is not returning a ResultSet object .
    If Oracle opens a cursor for these two methods, how should i close the open cursor.

  • Checking the status of the insert query in JSP

    frendz,
    i am working with JSP .i have some content to be inserted in the database.i have used the insert query in SQL for that.i am able to check whether it has been inserted properly in the SQL but i want to check the status of the insert query with its return value(so that i can confirm it does not return a error).so please help.

    The Statement#executeUpdate() returns an int with the row count. Get hold of it.
    Also see the Statement API: http://java.sun.com/javase/6/docs/api/java/sql/Statement.html
    Apart from this, I recommend you to use PreparedStatement instead. It will not only ease setting Java objects in a query (no hassle anymore with quotes), but it will also prevent you from SQL injections.
    Prepare here: http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
    SQL injections: http://en.wikipedia.org/wiki/SQL_injection

  • Need details on usage of "createStatement" of OCCI, for less parse calls

    Hi All,
    I am working on CPP code where i am using OCCI for connecting to database and perform actions like INSERT, UPDATE, DELETE etc. on different tables (which includes huge tables which contain millions of records).
    I have requested for AWR report from our DBA and during its analysis, i found that, number of "parse calls" for UPDATE and INSERT on two tables is too high.
    As part of code, what i am doing is to call a function called Updatetable, where i define Updatetable function as below:
    int Cdb::updatetable()
    Statement *stmt = conn->createStatement (" UPDATE table set data1 =:1 where data2 =:2");
    stmt->setInt(1, data1);
    stmt->setInt(2, data2);
    updateCnt = stmt->executeUpdate();
    return updateCnt;
    This function is called, once per "Oracle queue message" and which means, if i have 2000 messages, it will be called for 2000 times. Also gets parsed by 2000 times.
    I have tried to reduce parse counts, by declaring and defining "createStatement" outside this function, but end up with "Segmentation fault".
    So, please let me know if there is any other way to get the parse calls reduced.
    Thanks in Advance!

    Hi,
    The code seems to work well . But at certain times we get the following error related to my code as shown above.
    ORA-29283: invalid file operation
    ORA-06512: at "SYS.UTL_FILE", line 475
    ORA-29283: invalid file operation
    ORA-06512: at line 10This error occurs occassionally and on opening a new connection for oracle in TOAD and on executing the abvoe code I cannot see this error again.
    Regards,
    Vinesh

  • How to get updated by count value in database ?

    hi all,
    I created jsp page iin which insert,update,delete , query and queryall Functionalities are working...
    I need following,
    whenever i update a record i should get updated by, updated time and updated count.. to be stored in database...
    i achieved to store updated by and updated time...
    please help me how to get updated count:
    when ever a record is updated for first time updated count=1,
    for second time it should be 2 for third time it should be 3 and so onnnn
    please help me how to write this kind of function and kind of code help will be appriciated....

    if you want "number of updates" performed on each row to be persistive, you should have designed the schema with an extra field which keeps number of updates performed.
    to generic solution sql statement should have been written like
    INSERT INTO table (a,b,c,update_count) VALUES (1,2,3,4)
      ON DUPLICATE KEY UPDATE update_count=update_count+1;in this case even a insert statement will work, you wouldn't had to write another update statement.
    or if u want to use update statement only
    have an extra column "update_count" do "update_count=update_count+1" on each update statement, set initial default value to 0;
    and if u want to know how many rows have been updated
    as BalusC wrote
    BalusC wrote:
    PreparedStatement#executeUpdate() returns an int which represents the amount of affected rows.

  • Mapping data model to java classes and Interface.

    Need help in mappning my data model into java classes;
    Here are some of the details:
    Table, Poll:
    PollID int
    PollName varchar
    BusinessUnit varchar
    DisplaySchemeID int // reference to DisplayScheme table.
    Table, DisplayScheme
    DisplaySchemeID
    DisplaySchemeName
    etc
    Table, URL
    UrlID
    UrlName
    UrlDesc
    Table, PollURL
    PollURLID
    PollID
    UrlID
    PublishDate
    etc
    Table, Tag
    TagID
    TagName
    PollID
    So, a POLL is associate with a DisplayScheme.
    A Poll can have many URLs and a URL can be associate with many Polls , mapped in the PollURL table.
    and same is the situation with tags.
    Essentially I want to learn how to do one to many mappning and many to many mapping.
    Also to add, since I plan to use Ibatis for OR mapping.
    So I should a Parameter call to map for creaint a Poll. And to create a poll the form submitted will have:
    - PollName
    - URLs ( multiple )
    - one display scheme.
    - Tags ( many )
    So if you can show how to write a DAO createPoll method, then it would be great.
    Not sure if am asking a lot, but this would be a great example to move forward.

    The below is the sample DAO Class.
    For your case, you have to create your own PollBean with getters and setters and just pass the object to the method
    public int create(Connection con, ProjectBean projectBean) throws SQLException {
              int result = 0;
              String insertQuery = " INSERT INTO" +
                        " M_PROJECT(" +
                        " PROJECT_ID," +
                        " PROJECT_NAME," +
                        " PROJECT_DESCRIPTION) " +
                        " VALUES(?,?,?,?)";          
              initPrepareStmt(con, insertQuery);
              setString(projectBean.getProjectID());
              setString(projectBean.getProjectName());
              if(projectBean.getProjectDescription().equals("")){
                   setString(" ");
              }else{
                   setString(projectBean.getProjectDescription());
              result = executeUpdate();          
         return result;
         }

  • Primary key not available

    Hi!
    When i run my appication client to connect to Oracle9i database i have a next exception:
    javax.ejb.CreateException: java.lang.IllegalStateException: Primary key not available.
    In Oracle i set a primary key field ID.
    Here is my code:
    /* Generated by Together */
    package ejb;
    import javax.ejb.EntityBean;
    import javax.ejb.EntityContext;
    import javax.ejb.EJBException;
    import javax.ejb.CreateException;
    import java.sql.SQLException;
    import java.sql.Connection;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import java.sql.PreparedStatement;
    import javax.ejb.NoSuchEntityException;
    import java.sql.ResultSet;
    import javax.ejb.DuplicateKeyException;
    import javax.ejb.RemoveException;
    import java.util.Collection;
    import java.util.ArrayList;
    import javax.ejb.FinderException;
    import javax.sql.DataSource;
    import java.lang.Integer;
    import java.lang.String;
    import java.rmi.RemoteException;
    import javax.sql.*;
    import java.sql.DriverManager;
    public class TestingBean implements EntityBean {
    private EntityContext ctx;
    public Integer userID;
    public String userLogin;
    public String userPassword;
    public String userPrivilege;
    static private final String users_res_ref = "jdbc/Oracle";
    public void setEntityContext(EntityContext context) throws EJBException {
    System.out.println("EntityContext before = " + ctx);
    ctx = context;
    System.out.println("EntityContext after = " + ctx);
    public void unsetEntityContext() throws EJBException {
    ctx = null;
    public void ejbActivate() throws EJBException {
    public void ejbPassivate() throws EJBException {
    public void ejbRemove() throws EJBException {
    Connection con = null;
    PreparedStatement ps = null;
    try {
    con = getConnection();
    userID = (Integer)ctx.getPrimaryKey();
    ps = con.prepareStatement("DELETE FROM TLogon WHERE Id = ?");
    ps.setInt(1, userID.intValue());
    if (!(ps.executeUpdate() > 0)) {
    throw new RemoveException ("ejbLoad: Can't remove user - " + userID);
    catch (Exception e) {
    throw new EJBException(e);
    finally {
    closeStatement(ps);
    closeConnection(con);
    public void ejbStore() throws EJBException {
    Connection con = null;
    PreparedStatement ps = null;
    try {
    con = getConnection();
    ps = con.prepareStatement("UPDATE TLogon SET Login = ?, Password = ?, Privilege = ? WHERE Id = ?");
    ps.setString(1, userLogin);
    ps.setString(2, userPassword);
    ps.setString(3, userPrivilege);
    ps.setInt(4, userID.intValue());
    ps.executeUpdate();
    catch (Exception e) {
    throw new EJBException(e);
    finally {
    closeStatement(ps);
    closeConnection(con);
    public void ejbLoad() throws EJBException {
    Connection con = null;
    PreparedStatement ps = null;
    userID = (Integer)ctx.getPrimaryKey();
    try {
    con = getConnection();
    ps = con.prepareStatement("SELECT Id, Login, Password, Privilege FROM TLogon WHERE Id = ?");
    ps.setInt(1, userID.intValue());
    ps.executeQuery();
    ResultSet rs = ps.getResultSet();
    rs.next();
    userLogin = rs.getString("Login");
    userPassword = rs.getString("Password");
    userPrivilege = rs.getString("Privilege");
    catch (Exception e) {
    throw new EJBException("ejbLoad: Can't load user - " + userID);
    finally{
    closeStatement(ps);
    closeConnection(con);
    public Integer ejbCreate(Integer aUserID, String aUserLogin, String aUserPassword, String aUserPrivilege) throws CreateException, EJBException, SQLException {
    System.out.println("Inititialization parameters...");
    this.userID = aUserID;
    this.userLogin = aUserLogin;
    this.userPassword = aUserPassword;
    this.userPrivilege = aUserPrivilege;
    System.out.println("Setting connection to null...");
    Connection con = null;
    PreparedStatement ps = null;
    try {           
    System.out.println("Getting connection...");
    con = getConnection();
    System.out.println("EntityContext before getting primary key... = " + ctx);
    System.out.println("Getting primary key...");
    userID = (Integer)ctx.getPrimaryKey();
    System.out.println("Primary key is done...");
    ps = con.prepareStatement("INSERT INTO TLogon (Id, Login, Password, Privilege) VALUES (?,?,?)");
    System.out.println("Inserting data...");
    ps.setInt(1, userID.intValue());
    ps.setString(2, userLogin);
    ps.setString(3, userPassword);
    ps.setString(4, userPrivilege);
    ps.executeUpdate();
    return aUserID;
    catch (Exception e) {
    throw new CreateException(e.toString());
    finally{
    closeStatement(ps);
    closeConnection(con);
    public Integer ejbFindByPrimaryKey(java.lang.Integer pk) throws FinderException, EJBException {
    Connection con = null;
    PreparedStatement ps = null;
    try {
    con = getConnection();
    ps = con.prepareStatement("SELECT Id, Login, Password, Privilege FROM TLogon WHERE Id = ?");
    ps.setInt(1, pk.intValue());
    ps.executeQuery();
    ResultSet rs = ps.getResultSet();
    rs.next();
    return pk;
    catch(Exception e) {
    throw new FinderException (e.toString());
    finally {
    closeStatement(ps);
    closeConnection(con);
    public void ejbPostCreate(Integer aUserID, String aUserLogin, String aUserPassword, String aUserPrivilege) throws CreateException, EJBException, SQLException {
              /* Write your code here */
    public Collection ejbFindAllUsers() throws EJBException, FinderException {
    Connection con = null;
    PreparedStatement ps = null;
    try {
    con = getConnection();
    ps = con.prepareStatement("SELECT Id FROM TLogon");
    ps.executeQuery();
    ResultSet rs = ps.getResultSet();
    ArrayList v = new ArrayList();
    Integer pk;
    while(rs.next()) {
    pk = new Integer(rs.getInt(1));
    v.add(pk);
    return v;
    catch(Exception e) {
    throw new FinderException(e.toString());
    finally {
    closeStatement(ps);
    closeConnection(con);
    public Integer getUserID() throws RemoteException, EJBException {return userID;}
    public void setUserID(Integer param) throws RemoteException, EJBException {this.userID = param;}
    public String getUserLogin() throws RemoteException, EJBException {return userLogin;}
    public void setUserLogin(String param) throws RemoteException, EJBException {this.userLogin = param;}
    public String getUserPassword() throws RemoteException, EJBException {return userPassword;}
    public void setUserPassword(String param) throws RemoteException, EJBException {this.userPassword = param;}
    public String getUserPrivilege() throws RemoteException, EJBException {return userPrivilege;}
    public void setUserPrivilege(String param) throws RemoteException, EJBException {this.userPrivilege = param;}
    private Connection getConnection() throws SQLException {
    InitialContext initCtx = null;
    try {
    initCtx = new InitialContext();
    DataSource ds = (javax.sql.DataSource)initCtx.lookup("java:comp/env/" + users_res_ref);
    return ds.getConnection();
    catch (Exception e) {
    throw new EJBException(e);
    private void closeStatement(PreparedStatement ps) {
    try {
    if (ps != null) {ps.close();}
    catch (Exception e) {
    throw new EJBException(e);
    private void closeConnection(Connection con) {
    try {
    if(con != null) {con.close();}
    catch(Exception e) {
    throw new EJBException(e);
    What i do wrong?
    Please help!!!!

    Very BIG thank you!!!!
    That's right, but i must delete this method only in ejbCreate?
    And i have a next exception: java.sql.SQLException: ORA-00947: not enough values. Why?
    Here is my code db:
    CREATE TABLE "SYSTEM"."TLOGON" ("ID" NUMBER(20) NOT NULL, "LOGIN"
    VARCHAR2(20 byte) NOT NULL, "PASSWORD" VARCHAR2(20 byte) NOT
    NULL, "PRIVILEGE" VARCHAR2(20 byte) NOT NULL,
    CONSTRAINT "ID" PRIMARY KEY("ID")
    USING INDEX
    TABLESPACE "SYSTEM"
    STORAGE ( INITIAL 12K NEXT 12K MINEXTENTS 1 MAXEXTENTS
    2147483645 PCTINCREASE 50 FREELISTS 1 FREELIST GROUPS 1)
    PCTFREE 10 INITRANS 2 MAXTRANS 255)
    TABLESPACE "SYSTEM" PCTFREE 10 PCTUSED 40 INITRANS 1
    MAXTRANS 255
    STORAGE ( INITIAL 12K NEXT 12K MINEXTENTS 1 MAXEXTENTS 249
    PCTINCREASE 50 FREELISTS 1 FREELIST GROUPS 1)
    LOGGING
    And my client:
    package ejb.client;
    import javax.naming.Context;
    import javax.rmi.PortableRemoteObject;
    import ejb.TestingHome;
    import ejb.Testing;
    import java.util.Collection;
    import java.rmi.RemoteException;
    import javax.ejb.FinderException;
    import javax.naming.InitialContext;
    public class TestingClient {
    public static void main(String []args) {
    try {
    System.out.println("Step #1");
    Context initial = new InitialContext();
    System.out.println("Step #2");
    Object objref = initial.lookup("java:comp/env/ejb/SimpleTesting");
    System.out.println("Step #3");
    ejb.TestingHome home = (ejb.TestingHome)PortableRemoteObject.narrow(objref, ejb.TestingHome.class);
    System.out.println("Step #4");
    ejb.Testing aTesting;
    for(int i = 0; i < 3; i++) {
    String login = users[0];
    String password = users[i][1];
    String privilege = users[i][2];
    System.out.println("Adding user..." + login + "\n" + password + "\n" + privilege);
    home.create(new Integer(i+1), login, password, privilege);
    Integer i = new Integer(2);
    home.create(i, "Zatoka", "password", "admin");
    catch(Exception e) {
    e.printStackTrace();
    //private static String JNDI = "ejb.TestingHome";
    private final static String[][] users = {{"Zatoka","*****","admin"}, {"Ivanov","234fds","user"},{"Petrov","dcd2","user"}};
    BIG thanks!!!

  • Can anyone spot the syntax error?

    I've been looking at this for about a day now and can't see the error, which is:
    Insert Failed: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
      public String addSaleList(SaleList sL) {
        try {
          //Gets the connection to customer database.
          Class.forName(Driver);
          Connection myCon = DriverManager.getConnection(Url);
          System.out.println(sL.saleListID + " " + sL.saleID + " " + sL.product
                             + " " + sL.number);
          String sqlQry = "INSERT INTO salelist(saleID, product, number)" +
              "VALUES(?,?,?)";
          PreparedStatement myStmt = myCon.prepareStatement(sqlQry);
          myStmt.setInt(1, sL.saleID);
          myStmt.setString(2, sL.product);
          myStmt.setInt(3, sL.number);
          myStmt.executeUpdate();
          return "Sale confirmed";
        catch (Exception e) {
          System.out.println("Insert Failed: " + e);
          return ("Insert Failed: " + e);
      public class SaleList {
        public int saleListID;
        public int saleID;
        public String  product;
        public int  number;
        public SaleList(int saleListID, int saleID, String product, int number) {
          this.saleListID = saleListID;
          this.saleID = saleID;
          this.product = product;
          this.number = number;
      SaleList saleL = new SaleList(0,10,"b",2);
      lblStatus.setText(sM.addSaleList(saleL));

    Hey this is the stack trace:
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
         at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
         at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
         at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3150)
         at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execut(JdbcOdbcPreparedStatement.java:214)
    at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdateJdbcOdbcPreparedStatement.java:136)
         at myproject.SaleModel.addSaleList0 120 a 1
    (SaleModel.java:69)
         at myproject.SalesGUI.actionPerformed(SalesGUI.java:395)
         at java.awt.Button.processActionEvent(Button.java:382)
         at java.awt.Button.processEvent(Button.java:350)
         at java.awt.Component.dispatchEventImpl(Component.java:3615)
         at java.awt.Component.dispatchEvent(Component.java:3477)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

  • Problrm in prepared statement

    I am trying to updating a table using prepared statement using executeupdate(). I need to write to a reject file if my update fails , the rejected resultset. I have tried to use getresultset() on preparedstatement and it does not work. any sugessions please.
    fred

    Hi,
    An executeUpdate returns to you an integer and not a resultset.Hence you won't be getting any resultset.You can try checking for a nonzero number returned by executeUpdate() to signify a sucess.
    Hope this will help you.
    Anil.
    Developer Technical Support.
    Sun Microsystems,India.
    http://www.sun.com/developers/support

  • Database will not update! grr

    I am using an excel database to store a string "Verb" and a number "Type".
    Heres the thing:
    The update works IF excel has the database open and is displaying it. Then when i click the save button, I can see in excel that my verb has popped up. Then, when i close out of excel, it asks me to save, even though i have done nothing using excel. if i save, the data sent from my program remains, if i do not, it is not there when i open it again.
    If excel is never open, the function executeUpdate returns 1 which means it was successful, but if i open the database in my program in excel, the data is not there. Here's my functions:
    getConnection:
              String Driver = "";
              String Url = "";
              String Username = "";
              String Password = "";
              Connection Con = null;
              try
                   Driver = "sun.jdbc.odbc.JdbcOdbcDriver";
                   Url = "jdbc:odbc:Excel Files;DBQ=";
                   Url += FilePath+"\\"+FileName;
                   Username = "";
                   Password = "";
                   Class.forName(Driver); // load JDBC-ODBC driver
                   return DriverManager.getConnection(Url, Username, Password);
              catch (Exception e) {System.out.println("getConnection:  "+e.getMessage());}
              return(Con);
    and one that updates the data:
         String FilePath = DataBases.getRootDirectory();
         String FileName = "StemChange.xls";
         Connection Con = DataBases.getConnection(FilePath, FileName);
         Statement Command = null;
         String Update = "insert into [Sheet1$] (Verb, Type) values ('Acostar', 3)";
         System.out.println(Update);
         int i = 0;
         try
              Command = Con.createStatement();
              i = Command.executeUpdate(Update);
         } catch (SQLException e) {System.out.println("Execute: "+e.getMessage());}
         if (i == 1)
              System.out.println("Success");
         else
              System.out.println("Failed");
    Does anyone know how i can get this to update without ever using excel, otherwise the program is useless because you could just do it through excel anyway and i REALLY REALLY don't want that.
    thanks, lateralus

    1) Give due consideration to not using Excel. Access might be a good alternative. Excel is really not a database and thus can have all sorts of weirdness when you try and use it as a database.
    2) Close your connection. Due to ODBC shenanigans if you use a file based ODBC datasource then you need to close the connection in order to flush the changes to the file. Simply close the connection (which you should be doing anyway) and see if that helps ( it may). I would recommend not having the file also open in Excel at the same time.

Maybe you are looking for

  • HOW CAN WE ASSIGN THREE TASK LIST TO THREE DIFF PRODUCTION ORDER

    Respected All we have one material which is used for three places FIRST IN MILL1, 2ND IN MILL2 AND THIRD IN TRIMMER MILL. the only thing which differentiate this single material is  the production order. we have 3 different production order but one s

  • F.01 Balance Sheet-Report to see in company code wise

    Hi Experts Goodevening We are recently upgraded to ECC.6 version of SAP. The issue is, when we use Tcode F.01 relating to Balance Sheet Report it is giving the result in Business Area Wise of all the assets and liabilities. Is there any possiblility

  • Can't listen to more than one song itunes freezes on second song

    I want to listen to samples of songs prior to purchasing them. I can only listen to one sample. When I choose a second sample Itunes stops working and I can't close it.

  • How to use FM HR_READ_INFOTYPE

    Hello experts, I want to use FM HR_READ_INFOTYPE to read infotype 0000. I want to read the whole table PA0000 not only a certain pernr. So what value I have to pass to parameter pernr in order to read the whole infotype 0000 (table PA0000)? CALL FUNC

  • Partitions

    Hi all, db:oracle 9.2.0.4 os:solaris 10 we have a 100 + datawarehouse tables. each table is having size of 20 + Gb ,all are partitioned. how to get the below info on oracle partitions. partition name,max value,length,tablespace,compression,rows,block