Mysql's auto_increment in berkeley db

Hi,
I am coming to BDB from MySQL. I am using C API to create my first example.
Q: What would be the equivalent of MySQL's auto_increment field type in BDB ?
I read the docs, and it says QUEUE access type will use immutable record numbers, does it mean I can rely on it "forever"? Can i store them in another databases and assume the record will never change its record number unless it is deleted? (this is how it works in MySQL)
I also read about SEQUENCE type fields and saw the example. Just in case QUEUE's record doesn't behave like MySQL auto_increment I can go for DB_SEQUENCE, I just need to clear things up with the first question, because if QUEUE works for me using DB_SEQUENCE will be wasting precious CPU cycles.
Thanks in advance

user3882275 wrote:
Q: What would be the equivalent of MySQL's auto_increment field type in BDB ?
I read the docs, and it says QUEUE access type will use immutable record numbers, does it mean I can rely on it "forever"? Can i store them in another databases and assume the record will never change its record number unless it is deleted? (this is how it works in MySQL)A B-Tree access method stores data in a B+Tree and provides fast serial and random access to data. A Hash database stores data in a hash table and provides slightly faster random access to data. A Queue database stores data in a FIFO queue and a Recno database stores data using an increasing record number, no key is required.
Logical record numbers can be mutable or fixed: mutable, where logical record numbers can change as records are deleted or inserted, and fixed, where record numbers never change regardless of the database operation. It is possible to store and retrieve records based on logical record numbers in the Btree access method. However, those record numbers are always mutable, and as records are deleted or inserted, the logical record number for other records in the database will change. The Queue access method always runs in fixed mode, and logical record numbers never change regardless of the database operation. The Recno access method can be configured to run in either mutable or fixed mode.
So yes, when using the Queue access method, you can rely on it "forever". You can also use the Recno access method and configure it to run in the fixed mode.
Selecting an access method - http://download.oracle.com/docs/cd/E17076_02/html/programmer_reference/am_conf_select.html
Hope this helps,
Bogdan Coman

Similar Messages

  • MySQL's AUTO_INCREMENT and JDBC

    I have the following that doesnt seem to work. The custID field i haven't specified in the prepare statement (because it's an AUTO_INCREMENT value , but for some reason it won't work without it. Nothing is added to the table when the method is completely run.
    int rows = 0;
    Connection conn = getConnection();
    PreparedStatement pstmt = null;
    try{
          pstmt = conn.prepareStatement(
         "insert into Customers values(" +
        "?," + //customername
           pstmt.setString(1, customerBean.getCustomerName());
    catch (SQLException se)
        rollback(conn);
        System.out.println(msg);
         System.out.println(se);
         throw new Exception(se);
    } | Field | Type | Null | Key | Default | Extra |
    -------------------------------------------------------------+
    | CUST_ID | int(11) | NO | PRI | NULL | auto_increment |
    | CUST_NAME | varchar(100) | YES | | NULL | |
    Any ideas? I want a proper way of forumlating a query using a prepared statement and using the AUTO_INCREMENT value so that when a new row is added the cust_Id field is incremented.
    Another question, why is the SQLException not being caught? I have another method which gets all the rows from a table, if i change the prepared statement to an invalid table then it gives me an exception. I was previously using Oracle, SQLException was being caught when a duplicate entry was added.

    Doesn't work :(
    try {
         Connection conn = getConnection();
         stmt = conn.createStatement();
         stmt.executeUpdate(
         "INSERT INTO Customers (customerName) "
         + "values ('Hello World')");
    Of course it doesn't work.
    1. That's not what was suggested.
    2. It's going to throw an exception, because you don't have a column named "customerName", you have a column IN THE DATABASE named "cust_name"

  • How to get primary keys in some order with joins?

    Hi, I build BBS using BDB as backend database, forum database, topic database and post database share one environment. This BBS web application is multi-thread program. If user selects one forum, its topics will be listed in order of last reply time;selecting one topic, posts are listed in order of reply time as well.
    struct forum {
    UInt16 forumID;
    string forumName;
    string _lastPoster;      // who is the last one replied in this forum
    struct topic {
    UInt32 topicID;
    UInt16 forumID; // topic comes from this forum
    string title; // topic title
    UInt64 dateOfLastReply; // when last reply to this topic happen
    struct post {
    UInt64 postID;
    UInt32 topicID; // post comes from this topic
    string title; // post title as of topic
    UInt64 dateOfPost; // when this post is created
    I create one primary database and two secondary databases for topic, primary key is topicID, secondary key are forumID and dateOfLastReply respectively, and I want to show 1st 25 topics in latest reply time order on the 1st browser page, 2nd 25 topics on the 2nd browser page, and etc.
    if using SQL, it will be: SELECT topicID FROM topic WHERE forumID=xx ORDER BY dateOfLastReply DESC
    From performance perspective, I want get all topics id of one same forum, and need them come in reply time order, then retrieve topic one by one based on returned topicID, how can I do this? guess I have to use joins.
    Plus, do you have any suggestion about retrieval performance given the fact that topics retrieval will happen each time browser want to request the next page, that is, 2nd 25 topics of this forum?
    Is DB_DBT_MULTIPLE helpful to me?
    thanks.
    Edited by: tiplip on 2011-1-22 上午5:43
    Edited by: tiplip on 2011-1-22 下午5:52
    Edited by: tiplip on 2011-1-23 下午7:42

    Hi tiplip,
    Bellow I will describe how you can support "SELECT * FROM table WHERE X = key ORDER BY Y" queries using Berkeley DB, which, as you suspected, should be done by using a composite index.
    First of all, think of Berkeley DB as the storage engine underneath an RDBMS. In fact, Berkeley DB was the first "generic data storage library" implemented underneath MySQL. As such, Berkeley DB has API calls and access methods that can support any RDBMS query. However, since BDB is just a storage engine, your application has to provide the code that accesses the data store with an appropriate sequence of steps that will implement the behavior that you want.
    If you have two indices in SQL, each on a single column (call them X and Y), and you do:
    SELECT * FROM table WHERE X = key ORDER BY Y;then there are three plausible query plans:
    (1) scan the whole table, ignore both indices, filter by X = key then sort by Y;
    (2) use the index on Y to scan all rows in the required order, filter by X = key;
    (3) use the index on X, find the matching rows, then sort by Y.
    There are cases where (1) would be fastest, because it has all of the columns from one scan (the other query plans will do random lookups on the primary for each row). This assumes that the data can fit into memory and the sort is fast.
    Query plan (2) will be fastest if the selectivity is moderate to high, looking up rows in the main table is fast, and sorting the rows is very slow for some reason (e.g., some complex collation).
    Query plan (3) will be fastest if the selectivity is small (only a small percentage of the rows in the table matches). This should be the best case for us, making it the best choice in a Berkeley DB key/value application.
    The optimal plan would result from having a composite index on (X, Y), which can return just the desired rows in the desired order. Of course, it does cost additional time and space to maintain that index. But note that you could have this index instead of a simple index on X: it can be used in any query the simple index could be used in.
    Records in Berkeley DB are (key, value) pairs. Berkeley DB supports only a few logical operations on records. They are:
    * Insert a record in a table.
    * Delete a record from a table.
    * Find a record in a table by looking up its key.
    * Update a record that has already been found.
    Notice that Berkeley DB never operates on the value part of a record. Values are simply payload, to be stored with keys and reliably delivered back to the application on demand. Both keys and values can be arbitrary byte strings, either fixed-length or variable-length.
    So, in case of a "SELECT * FROM X WHERE id=Y ORDER BY Z" query, our suggestion, from Berkeley DB's point of view, would be for you to use a composite index (as it would be in SQL), where a string created as X_Y should do the trick, as explained in the following scenario.
    Primary:
        X Y
    1 10 abc
    2 10 aab
    3 20 bbc
    4 10 bba
    5 20 bac
    6 30 cbaSecondary:
    10_aab 2
    10_abc 1
    10_bba 4
    20_bac 5
    20_bbc 3
    30_cba 6If the query looks like this:
    'SELECT * FROM primarydb WHERE X = 10 ORDER by Y'the application can run a cursor on the secondary and begin the loop with the DB_SET_RANGE flag on 10. When iterating with DB_NEXT, this will return:
    2 10 aab
    1 10 abc
    4 10 bbcThe application must check for the end of the range inside the loop, in this case it should stop when it hits 20_bac.
    As in SQL, retrieving by a secondary key is remarkably similar to retrieving by a primary key and the Berkeley DB call will look similar to its primary equivalent.
    tiplip wrote:
    Plus, do you have any suggestion about retrieval performance given the fact that topics retrieval will happen each time browser want to request the next page, that is, 2nd 25 topics of this forum?As you are concerned about the performance, I think this would be the fastest solution. Of course, you can tune the performance at a later time, after you have the functionality in place. What I think you should do first is to increase the cache size and test with a bigger database page size, and maybe to configure the transactional subsystem (in case you use one).
    If you are not very familiar with how to implement the above in BDB, please read the Guide to Oracle Berkeley DB for SQL Developers, available at: http://www.oracle.com/technetwork/articles/seltzer-berkeleydb-sql-086752.html
    You will also need to be familiar with the following documentation:
    Related documentation pages:
    Secondary indexes - http://download.oracle.com/docs/cd/E17076_01/html/programmer_reference/am_second.html
    Cursor operations - http://download.oracle.com/docs/cd/E17076_01/html/programmer_reference/am_cursor.html#am_curget
    DBcursor->get() - http://download.oracle.com/docs/cd/E17076_01/html/api_reference/C/dbcget.html
    DB_SET_RANGE - http://download.oracle.com/docs/cd/E17076_01/html/api_reference/C/dbcget.html#dbcget_DB_SET_RANGE
    If my answer helps you with your question, please go ahead and rate it as Helpful or Correct, and the forum thread as answered. For each unrelated question, please create a new forum thread.
    Good luck with building your forum application,
    Bogdan Coman
    PS: If you are a BDB licensed customer, you can also use My Oracle Support (https://support.oracle.com) to visit the KM note 1210173.1, that discusses the same topic.

  • CRUD insert problems.

    Hello all,
    I was wondering about DB operations in JSF pages, so I took a look over the Single Page CRUD example. What hitted me was there is a need for a two step insertion, first by issuing a select in search for the biggest ID of the primary key, and after that the insertion of the element with that obtained biggest ID + 1. I see at least 2 problems with this approach:
    1. Concurrency issues.What happends if 2 users are issuing at the same time an insert operation over the same table? There is the possiblity of getting the same ID to insert, and the first one could insert, but the second one would fail even if it's request is logically corect (validated & converted). I see three solutions over the insert problem:
    a. lock on the database (if it's possible).
    b. using a synchronized block in the application bean to get the ID and insert.
    c. using DB specific constructs (e.g. MySQL's AUTO_INCREMENT)
    2. Overhead issues. Why doing in two steps an operation that should be just an insert? Previous a. an b. approaches do not solve our overhead problem, because we still have two steps in insertion; we only synchronize them.
    I was wondering which is the best practice for production quality web applications. Personally because I've picked MySQL as DB I've used AUTO_INCREMENT, but the immediate huge and obvious drawback is dumping DataProvider's capability of changing the storage medium at a glance.

    I'm not sure if I entirely understood your questions here.
    - Concurrency problem.
    database bound Data provider underneath uses CachedRowset, which uses SyncProvider to take care of concurrency problem. If the default RIOptimisticProvider is not enough, it possible to register other more sophisticated SyncProvider.
    You can read about it here.
    http://java.sun.com/j2se/1.5.0/docs/api/javax/sql/rowset/CachedRowSet.html
    - Overhead issue
    I believe, it is possible to let the DB auto increment the primary key field, and left it out in the insertion from data provider.
    - Winston
    http://blogs.sun.com/roller/page/winston?catname=Creator

  • Setup basic install as a service on XP

    Just wondering if anyone knew how to create a service in the control panel to start and stop SOA suite (Basic install). For some reason only the advanced version creates the service by default.
    cheers
    James

    Hi,
    How to run BDB as a Windows Service and
    how to start the BDB with a simple inital
    database like the Postgresql DB or MySQL?Berkeley DB is an embedded database which provides fast, portable, reliable, local persistence with zero administration.
    As an embedded databse Berkeley DB is in fact a transactional storage engine for un-typed data in basic key/value data structures. Thus, Berkeley DB can't be run as a windows service, the way other RDBMSes act. Berkeley DB comes with libraries that you can integrate with your application and various useful utilities. There isn't a web interface nor an administration tool like phpMyAdmin for MySQL to manage your Berkeley DB databases, this is done via the APIs provided by Berkeley DB.
    Regards,
    Andrei

  • How to retrieve the Identity/auto_increment fireld after an insert in MYSQL

    I have a table in MYSQL 5.0 with an auto_increment key. I can insert records into the table with no problems, but how do I know what the generated key is?
    Thanks for any help,
    Keith

    Hi,
    Can you be more precise?
    After inserting a records into the database the auto_increment field will be filled in automatically by mysql.
    When you run a SELECT * FROM <tablename> it will show up. If it shows up as 0 you forgot to refresh the dataprovider.

  • How to re-order automatically the number of primary key column in MySql that has been set as auto_increment if one of the row deleted?

    Hello,
    Can anyone show me the way how to re-oder automatically the number of primary key that has been set as auto_increment in mysql database when the row deleted?
    example:
    No (primary key=auto increment)|
    Name |
    AGE |
    1
        | JO
    | 21
    |
    2
        | Kyle
    | 25
    |
    3
        | Macy
    | 30
    |
    When delete 1 row:
    No (primary key=auto increment)|
    Name |
    AGE |
    1
        | JO
    | 21
    |
    2
        | Macy
    | 30
    |

    Hello,
    This is not a VB.NET question, best to ask this question in
    MySQL forum.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

  • Mysql auto_increment.

    I'm trying to use jdeveloper to desing my db structure using mysql, how i set an id field as autoincrement ?
    thanks in advance.

    Actually, I believe that the auto-increment support is in the current
    2.5.0 release (beta 2).
    -Patrick
    On Fri, 11 Apr 2003 22:11:02 -0400, Marc Prud'hommeaux wrote:
    Note that the feature isn't available in the current beta, but it will
    be available in the final release (which will be out "real soon now").
    In article <[email protected]>, Abe
    White wrote:
    I believe we've added some auto-increment support in our 2.5 beta,
    available here:
    http://solarmetric.com/Software/beta/2.5.0
    Patrick Linskey
    SolarMetric Inc.

  • How to strart auto_increment from 500000? (mysql)

    Hi all,
    quick question, I have a table with the following prop:
    1. ID
    2. fname
    3. lname
    the Id is auto_increment. I wonder how can I start the count from say 50000?
    thank you

    thank you
    ALTER TABLE tbl AUTO_INCREMENT = 100;
    solved!

  • A tale of a Berkeley DB project: Success and future developements

    The site http://www.electre.com is an on-line catalog of all published French books (close to 1 million of them), from the 1970’s to today, with pricing and availability information for professional users.
    The entire book database and search engine was developed with Berkeley DB. The site runs relatively problem free, and owes much to the stability and quality of the Berkeley DB source code. Moreover, the software is sold as an intranet version and runs on remote configurations that are out of our direct control. And yet, we don’t get much problem reports from these remote sites.
    Development started in 2002. Using Berkeley DB was my decision. It was, with hindsight, a very good decision, but it would be hypocritical to affirm I knew all along it would work out so well. It was partly a gamble, and partly a calculated risk. I am not ashamed to confess that when I finally made the decision to go with Berkeley DB, there were some key areas in the technical design I had no clue how to tackle. Needless to say, any flaws that remain in this area are due to lack of knowledge and lack of foresight on my part, not because of some flaw in Berkeley DB.
    What convinced me 4 years ago to “go for it” was Sleepycat’s no-nonsense approach to support from guys like Michael Cahill, Keith Bostic, John Merrells, Dave Seglau, Michael Ubell, Liz Pennel and others. Support was sending a message to [email protected]. Replies were never more than a couple of days away (including time zone differences). There was always something comforting when you read a reply from someone who says he “owns your problem” (especially when you also saw that someone’s name in the source code <g>). The majority of support questions were asked during evaluation and product development, before even a single dime was paid to Sleepycat. (Now that we sell the product as a closed source Intranet solution, we gladly pay the required license fees, of course). The fact that the project development went so well was in no small part thanks to the competence and reliability of the people I communicated with. I never expressed my thanks, so now is as good a time as any to do so. Thanks, guys (and gals).
    When Sleepycat was bought by Oracle, it was rumored that the goal was ultimately “to kill the product”. I thought that was ridiculous and an exaggeration by some paranoid people (especially from the MySQL-camp). I understand that Oracle is a big company, and that things are done differently now. Besides, how do you “kill” a product? I didn’t know until I hit my first support question “post-Sleepycat”. So now I do: you kill a product not directly, but, but by a process of what I call “incremental discouragement”. It’s a subtle, 3-pronged approach:
    1)     Erect bureaucratic barriers between competent people and your customers. No more [email protected], but a slow and unwieldy web site and a support procedure hiding behind numbers and requiring a 2 hour training session. I’m not sure how I’m going to motivate to management a 2 hour training session for a product we’ve been using for the past 4 years, and which I now master sufficiently to reduce my support requests to about 3 a year, and for which the only difference is a change of company name. There’s a “free” forum, but the primary motivation for it seems to be to allow users to support themselves. Yes, questions are answered on the forum… but compared to the level of support I’ve been accustomed to from the same people in the past, I can’t help noticing something has changed… and not for the better. Some questions aren’t even acknowledged, though they are read over 300 times.
    2)     Add useless levels of indirection: when we sell an intranet, we asked Sleepycat to mail us an invoice, which we got within the week. Now we ask Oracle the same thing: the last time we did this was on November 27 of last year, and we still waiting for someone from “the Belgian office” to contact us. The only reply we got was from someone telling us our request would be passed on: a level of indirection not exactly adding value.
    3)     Increase useless Information Noise: www.sleepycat.com was all about Berkeley DB and related products. Look at any page on the www.oracle.com site supposedly about Berkely DB and count the number of items and links pointing to products that have nothing to do with Berkeley DB. It’s like that famous analogy: you’re only interested in a banana, and you must take the whole gorilla.
    Berkeley DB is the fire behind the electre.com site. Our customers are satisfied, so this is not going to change for this version. But this developer is now convinced to view Berkeley DB as a medium to long-term liability. The fire will be kept alive for the remainder of this electre.com version, but for future versions and other similar projects, other solutions will have to be found. These other solutions will involve a similar gamble as the one I made a few years ago with Berkeley DB. My only hope is to meet similar competence, friendliness and professionalism, but without the overhead and bureaucracy of an organization for which the product is not even part of the core business.

    Vincent,
    I hear the frustration and concern in your post. I'd like to assure you that we're still here doing what we've done in the past and that your business is valuable to us, don't give up yet! :)
    Moving from a company of 30 people to a company of >50,000 people has been an interesting transition for us as well. I have to say that honestly, things are pretty good here inside the realm of Oracle. Of course, some things were bound to change. Oracle has processes in place to acquire and grow companies and that is their intended goal with Sleepycat's Berkeley DB products. As such, some customer facing processes have changed and our home on the internet has been incorporated into the oracle.com site. The interesting thing to me is that even within Oracle's infrastructure you, the customer, are not really much further away from our engineers and support staff than before. Your suggestions, concerns, questions and bugs go directly to us via the same people pre-acquisition for the most part, although that staff is growing. With these OTN forums you have a way to speak directly to most of the Sleepycat staff, 99% of whom are still here at Oracle nearly one year post acquisition. So, I'd argue that we've done a great job of keeping that small company feeling in one of the largest software providers around.
    Our web content is 80% identical to that which was on the sleepycat.com sites. Bookmarking one or two locations within Oracle and OTN will get you straight to that information. Sure, there are other product references floating around on the same page and we hope that over time Berkeley DB products and other Oracle products complement each other when used in combination. In general, I believe that most of the web experience is identical with different style sheets and a few extra links.
    Support for eval customers continues to be something we provide free of charge via these forums and in private email conversations with our staff. This is unchanged. Ownership of customer issues is much the same as well and we do still use '[email protected]' for tracking issues once opened. We agree that '[email protected]' method of communication was simple and highly effective for us and our customers. We are working with Oracle's support infrastructure to consider adopting similar methods. This is another reason Oracle purchased Sleepycat, to learn from our efficient effective operational model. This is something that is ongoing, in the mean time we still track issues behind the scenes the same way as before with the added information provided by TARs so that we fit into the overall Oracle support infrastructure.
    The rumors of our early demise are highly exaggerated. Berkeley DB products are alive and well in Oracle. Just look at the releases we've made in the past 12 months.
    As for our three pronged attack. ;-)
    1. The distance between first contact with support and helpful information has, in some ways, increased. This is due to the Oracle infrastructure for support that manages all Oracle products. The forums are the replacement for the discussion email lists we managed at sleepycat.com. We're managing a much larger amount of traffic than in the past and most of it is done with the same Berkeley DB engineering team you've come to know and love. Maybe we need to make it more obvious when we answer a question by having a signature indicating who we are, sometimes that's not obvious. As to the particular question you posed, I don't know what happened but the same thing can happen on an email list. My apologies for the lack of a response.
    2. Oracle has a huge sales force worldwide. We're only beginning to fully function within this new infrastructure. Sorry we dropped the ball on your sales inquiry, rest assured that we're interested in all commercial deals. Once connected into the Belgium office you'll have a direct relationship, as before, with a sales rep for your use of Berkeley DB.
    3. I've already talked about this. Oracle has many products, we're just one of those. We have to fit within the overall site structure. For the most part I'd give us an A- or B+ for transitioning our sleepycat.com information into oracle.com and OTN.com. If you have suggestions as to how we might improve that, drop me a line I'm all ears.
    In general I'd like to believe that you and other developers like you will find that our place in Oracle doesn't prevent you from choosing Berkeley DB. Certainly it is a bigger company with some additional process overhead, but hopefully not so much that it prevents you from remaining a loyal customer and someone who would recommend us to others.
    regards,
    -greg
    Gregory Burd [email protected]
    Product Manager, Berkeley DB/JE/XML Oracle Corporation

  • Generating CSV file with column names and data from the MySQL with JAVA

    Hi all,
    Give small example on ...
    How can I add column names and data to a CSV from from MySQL.
    like
    example
    sequence_no, time_date, col_name, col_name
    123, 27-apr-2004, data, data
    234, 27-apr-2004, data, data
    Pls give small exeample on this.
    Thanks & Regards
    Rama Krishna

    Hello Rama Krishna,
    Check this code:
    Example below exports data from MySQL Select query to CSV file.
    testtable structure
    CREATE TABLE testtable
    (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    text varchar(45) NOT NULL,
    price integer not null);
    Application takes path of output file as an argument.
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    public class automateExport {
        public static void main(String[] args) {
            DBase db = new DBase();
            Connection conn = db.connect(
                    "jdbc:mysql://localhost:3306/test","root","caspian");
            if (args.length != 1) {
                System.out.println(
                        "Usage: java automateExport [outputfile path] ");
                return;
            db.exportData(conn,args[0]);
    class DBase {
        public DBase() {
        public Connection connect(String db_connect_str,
                String db_userid, String db_password) {
            Connection conn;
            try {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                conn = DriverManager.getConnection(db_connect_str,
                        db_userid, db_password);
            } catch(Exception e) {
                e.printStackTrace();
                conn = null;
            return conn;
        public void exportData(Connection conn,String filename) {
            Statement stmt;
            String query;
            try {
                stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                        ResultSet.CONCUR_UPDATABLE);
                //For comma separated file
                query = "SELECT id,text,price into OUTFILE  '"+filename+
                        "' FIELDS TERMINATED BY ',' FROM testtable t";
                stmt.executeQuery(query);
            } catch(Exception e) {
                e.printStackTrace();
                stmt = null;
    Greetings,
    Praveen Gudapati

  • Why MYSQL error come

    when I deploy cmp bean on jboss-3.2.2 it gives following error (I use lomboz plugins):-
    5:53:11,197 INFO [EjbModule] Deploying FirstStat
    15:53:11,728 WARN [EntityContainer] No resource manager found for jdbc/MySqlDs
    15:53:13,320 ERROR [EntityContainer] Starting failed
    org.jboss.deployment.DeploymentException: Error in jbosscmp-jdbc.xml : datasource-mapping MYSQL not found
         at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCEntityMetaData.<init>(JDBCEntityMetaData.java:433)
         at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCApplicationMetaData.<init>(JDBCApplicationMetaData.java:310)
    Note:- Stateless or stateful bean created with dao, accessing of database normally.
    FirstStatBean.class
    * Created on Jan 23, 2006
    * TODO To change the template for this generated file go to
    * Window - Preferences - Java - Code Style - Code Templates
    package chaman.com;
    import java.rmi.RemoteException;
    import javax.ejb.EJBException;
    import javax.ejb.EntityBean;
    import javax.ejb.EntityContext;
    * <!-- begin-user-doc --> You can insert your documentation for '<em><b>FirstcmpBean</b></em>'. <!-- end-user-doc --> *
    <!-- begin-lomboz-definition -->
    <?xml version="1.0" encoding="UTF-8"?>
    <lomboz:EJB xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:lomboz="http://lomboz.objectlearn.com/xml/lomboz">
    <lomboz:entity>
    <lomboz:entityEjb>
    <j2ee:display-name>Firstcmp</j2ee:display-name>
    <j2ee:ejb-name>Firstcmp</j2ee:ejb-name>
    <j2ee:ejb-class>chaman.com.FirstcmpBean</j2ee:ejb-class>
    <j2ee:persistence-type>Container</j2ee:persistence-type>
    <j2ee:prim-key-class>java.lang.Integer</j2ee:prim-key-class>
    <j2ee:cmp-version>2.x</j2ee:cmp-version>
    <j2ee:abstract-schema-name>ecr</j2ee:abstract-schema-name>
    <j2ee:primkey-field>id</j2ee:primkey-field>
    </lomboz:entityEjb>
    <lomboz:fieldMappings>
    <lomboz:fieldName>id</lomboz:fieldName>
    <lomboz:fieldType>java.lang.Integer</lomboz:fieldType>
    <lomboz:columnName>id</lomboz:columnName>
    <lomboz:jdbcType>VARCHAR</lomboz:jdbcType>
    <lomboz:sqlType>INT</lomboz:sqlType>
    <lomboz:readOnly>false</lomboz:readOnly>
    <lomboz:primaryKey>true</lomboz:primaryKey>
    </lomboz:fieldMappings>
    <lomboz:fieldMappings>
    <lomboz:fieldName>fname</lomboz:fieldName>
    <lomboz:fieldType>java.lang.String</lomboz:fieldType>
    <lomboz:columnName>fname</lomboz:columnName>
    <lomboz:jdbcType>VARCHAR</lomboz:jdbcType>
    <lomboz:sqlType>VARCHAR</lomboz:sqlType>
    <lomboz:readOnly>false</lomboz:readOnly>
    <lomboz:primaryKey>false</lomboz:primaryKey>
    </lomboz:fieldMappings>
    <lomboz:fieldMappings>
    <lomboz:fieldName>lname</lomboz:fieldName>
    <lomboz:fieldType>java.lang.String</lomboz:fieldType>
    <lomboz:columnName>lname</lomboz:columnName>
    <lomboz:jdbcType>VARCHAR</lomboz:jdbcType>
    <lomboz:sqlType>VARCHAR</lomboz:sqlType>
    <lomboz:readOnly>false</lomboz:readOnly>
    <lomboz:primaryKey>false</lomboz:primaryKey>
    </lomboz:fieldMappings>
    <lomboz:fieldMappings>
    <lomboz:fieldName>phone</lomboz:fieldName>
    <lomboz:fieldType>java.lang.String</lomboz:fieldType>
    <lomboz:columnName>phone</lomboz:columnName>
    <lomboz:jdbcType>VARCHAR</lomboz:jdbcType>
    <lomboz:sqlType>VARCHAR</lomboz:sqlType>
    <lomboz:readOnly>false</lomboz:readOnly>
    <lomboz:primaryKey>false</lomboz:primaryKey>
    </lomboz:fieldMappings>
    <lomboz:tableName>address</lomboz:tableName>
    <lomboz:dataSourceName></lomboz:dataSourceName>
    </lomboz:entity>
    </lomboz:EJB>
    <!-- end-lomboz-definition -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.bean name="Firstcmp"
    *     jndi-name="Firstcmp"
    *     type="CMP"
    * primkey-field="id"
    * schema="ecr"
    * cmp-version="2.x"
    * data-source=""
    * @ejb.persistence
    * table-name="address"
    * @ejb.finder
    * query="SELECT OBJECT(a) FROM ecr as a"
    * signature="java.util.Collection findAll()"
    * @ejb.pk class="java.lang.Integer"
    * @ejb.resource-ref res-ref-name="jdbc/MySqlDs"
    * res-auth="Container"
    * @jbos.resource-ref res-ref-name="jdbc/MySqlDs"
    * jndi-name="java:/MySqlDS"
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract class FirstcmpBean implements javax.ejb.EntityBean {
    protected EntityContext eContext;
    * <!-- begin-user-doc -->
    * The ejbCreate method.
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.create-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public java.lang.Integer ejbCreate(Integer id, String fname,String lname, String phone ) throws javax.ejb.CreateException {
    // EJB 2.0 spec says return null for CMP ejbCreate methods.
    // TODO: YOU MUST INITIALIZE THE FIELDS FOR THE BEAN HERE.
    // setMyField("Something");
    // begin-user-code
         setId(id);
         setFname(fname);
         setLname(lname);
         setPhone(phone);
    return null;
    // end-user-code
    * <!-- begin-user-doc -->
    * The container invokes this method immediately after it calls ejbCreate.
    * <!-- end-user-doc -->
    * @generated
    public void ejbPostCreate(Integer id, String fname,String lname, String phone) throws javax.ejb.CreateException {
    // begin-user-code
    // end-user-code
    * <!-- begin-user-doc -->
    * CMP Field id
    * Returns the id
    * @return the id
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.persistent-field
    * @ejb.persistence
    * column-name="id"
    * jdbc-type="VARCHAR"
    * sql-type="INT"
    * read-only="false"
    * @ejb.pk-field
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract java.lang.Integer getId();
    * <!-- begin-user-doc -->
    * Sets the id
    * @param java.lang.Integer the new id value
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract void setId(java.lang.Integer id);
    * <!-- begin-user-doc -->
    * CMP Field fname
    * Returns the fname
    * @return the fname
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.persistent-field
    * @ejb.persistence
    * column-name="fname"
    * jdbc-type="VARCHAR"
    * sql-type="VARCHAR"
    * read-only="false"
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract java.lang.String getFname();
    * <!-- begin-user-doc -->
    * Sets the fname
    * @param java.lang.String the new fname value
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract void setFname(java.lang.String fname);
    * <!-- begin-user-doc -->
    * CMP Field lname
    * Returns the lname
    * @return the lname
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.persistent-field
    * @ejb.persistence
    * column-name="lname"
    * jdbc-type="VARCHAR"
    * sql-type="VARCHAR"
    * read-only="false"
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract java.lang.String getLname();
    * <!-- begin-user-doc -->
    * Sets the lname
    * @param java.lang.String the new lname value
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract void setLname(java.lang.String lname);
    * <!-- begin-user-doc -->
    * CMP Field phone
    * Returns the phone
    * @return the phone
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.persistent-field
    * @ejb.persistence
    * column-name="phone"
    * jdbc-type="VARCHAR"
    * sql-type="VARCHAR"
    * read-only="false"
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract java.lang.String getPhone();
    * <!-- begin-user-doc -->
    * Sets the phone
    * @param java.lang.String the new phone value
    * <!-- end-user-doc -->
    * <!-- begin-xdoclet-definition -->
    * @ejb.interface-method
    * <!-- end-xdoclet-definition -->
    * @generated
    public abstract void setPhone(java.lang.String phone);
         /* (non-Javadoc)
         * @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext)
         public void setEntityContext(EntityContext arg0) throws EJBException,
                   RemoteException {
              // TODO Auto-generated method stub
    this.eContext= arg0;
         /* (non-Javadoc)
         * @see javax.ejb.EntityBean#unsetEntityContext()
         public void unsetEntityContext() throws EJBException, RemoteException {
              // TODO Auto-generated method stub
    this.eContext=null;
    jbosscmp-jdbc.class
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">
    <jbosscmp-jdbc>
    <defaults>
    <datasource>java:/MySqlDS</datasource>
    <datasource-mapping>MYSQL</datasource-mapping>
    <preferred-relation-mapping>foreign-key</preferred-relation-mapping>
    </defaults>
    <enterprise-beans>
    <!--
    To add beans that you have deployment descriptor info for, add
    a file to your XDoclet merge directory called jbosscmp-jdbc-beans.xml
    that contains the <entity></entity> markup for those beans.
    -->
    <entity>
    <ejb-name>Firstcmp</ejb-name>
    <table-name>address</table-name>
    <cmp-field>
    <field-name>id</field-name>
    <column-name>id</column-name>
    <jdbc-type>VARCHAR</jdbc-type>
    <sql-type>INT</sql-type>
    </cmp-field>
    <cmp-field>
    <field-name>fname</field-name>
    <column-name>fname</column-name>
    <jdbc-type>VARCHAR</jdbc-type>
    <sql-type>VARCHAR</sql-type>
    </cmp-field>
    <cmp-field>
    <field-name>lname</field-name>
    <column-name>lname</column-name>
    <jdbc-type>VARCHAR</jdbc-type>
    <sql-type>VARCHAR</sql-type>
    </cmp-field>
    <cmp-field>
    <field-name>phone</field-name>
    <column-name>phone</column-name>
    <jdbc-type>VARCHAR</jdbc-type>
    <sql-type>VARCHAR</sql-type>
    </cmp-field>
    </entity>
    </enterprise-beans>
    </jbosscmp-jdbc>

    thank u for sending solution.
    cmp file successfully deployed but one prob. creats, when i send parameters values of
    create method (create("suman","kumar")) through client file, it inserts data correctly in table
    but it gives following error(Table stru:- (id int auto_increment primary key, fname varchar(20), lname varchar(20)):-
    javax.ejb.CreateException: Primary key for created instance is null.
         at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:520)
         at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:208)
         at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:269)
         at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:736)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(

  • Problem with getImportedKeys() in MySQL

    Hi everyone,
    I am using JDK1.5.0 and the jdbc "mysql-connector-java-3.0.16"
    I've been trying to get the foreign keys from a MySQL 4.1 database using the getImportedKeys() method of the DatabaseMetaData class,but the method returns a ResultSet,which is null!
    However, I noticed that the getPrimaryKeys() method (which needs the same arguments as the getImportedKeys() one) works just fine and that puzzles me.
    Can anybody help me? Is this a known bug of MySQL?
    Thanks in advance.

    Indeed,previous MySQL versions did not support foreign keys...
    However,MySQL Server 4.1 allows foreign keys as you can see:
    CREATE TABLE `companies` (
    `Company_Id` int(6) unsigned NOT NULL auto_increment,
    `Name` varchar(11) default NULL,
    `Artist_Id` int(6) unsigned NOT NULL default '0',
    PRIMARY KEY (`Company_Id`),
    KEY `Artist_Id` (`Artist_Id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    INSERT INTO `companies` VALUES (1,'heaven',1);
    INSERT INTO `companies` VALUES (2,'emi',3);
    # Foreign keys for table companies
    ALTER TABLE `companies`
    ADD FOREIGN KEY (`Artist_Id`) REFERENCES `artists` (`Artist_Id`);
    Any further help? :-)

  • Select returns negative values for unsigned datatypes in MySQL DB

    Hi, I have a table in a MySQL database where some fields are declared as "unsigned".
    Example:
    CREATE TABLE countries (
    Country_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    Number SMALLINT UNSIGNED NOT NULL
    My problem is when inside a .xsql file, I try to do a select:
    <xsql:query>
    select Number from countries where Country_id="15"
    </xsql:query>
    If inside the Database, Number always goes from 0 to 65535 (UNSIGNED SMALLINT),
    the resulting XML of that query will always show negative values if Number is
    bigger than 32767 (so it ignores the "UNSIGNED").
    Have you seen something like this before? Do you kwno what I'm doing wrong or what
    can I do to retrieve the values unsigned?
    Thanks a lot!
    David

    hi muneer
    >
    We are facing a strange issue in our R12.1.3 Ebiz instance (DB 11.2.0.1) - Solaris Sparc 64 bit - 2 node (1 node Apps, 1 node DB).
    Some of the purchase orders are having a negative purchase order number.
    SQL> select segment1 from PO_HEADERS_ALL where segment1 < '0';
    SEGMENT1
    -7951814
    -8960847please see
    Error: Purchase Order Creation Could Not Be Initiated, But PO Was Created With Negative PO Number And No Distributions [ID 789464.1]     To Bottom     
    PO Creation Process Failed In Sourcing And Creates Document With Negative Numbers [ID 1479616.1]
    Purchase Order Receipt FAQ (P4312) [ID 1306869.1]
    How it could happen. Any suggestions please !looks like a bug
    Can a Purchase Order (PO) Be Created With Negative Quantity or Price? [ID 241389.1]
    AppsMasti
    Sharing is caring

  • Help on locking MySQL tables (many can read, but only one can write) Java

    Hi there,
    I have a question regarding locking of tables so that only one person can write to the file, but many are able to read the files (or tables entities).
    I am not sure if I need to lock the tables in my Java code or do I lock the tables within the MySQL syntax. I'm just a little confused on the matter.
    This java code is a working prototype of inserting a customer data into the database and that works fine. I just don't know how to implement it so that only one person can update the table at a time.
    Here is the Customer.java code that I have written.
    Help would be greatly appreciated, thanks so much.
    package business;
    //~--- non-JDK imports --------------------------------------------------------
    import shared.info.CustomerInfo;
    //~--- JDK imports ------------------------------------------------------------
    import java.sql.*;
    * @author
    public class Customer {
        static Connection    con  = DBConnection.getConnection();
        private CustomerInfo info = new CustomerInfo();
        private String               customerID;
        private String               firstName;
        private String               lastName;
        private String               email;
        private String               addressID;
        private String               homePhone;
        private String               workPhone;
        private String               unitNum;
        private String               streetNum;
        private String               streetName;
        private String               city;
        private String               provinceState;
        private String               country;
        private String               zipPostalCode;
        public Customer(String id) {
            try {
                PreparedStatement pstmt = con.prepareStatement("SELECT * FROM " +
                        "Customer NATURAL JOIN Address WHERE CustomerID = ?");
                pstmt.setString(1, id);
                ResultSet rs = pstmt.executeQuery();
                while (rs.next()) {
                    customerID    = rs.getString("CustomerID");
                    firstName     = rs.getString("FirstName");
                    lastName      = rs.getString("LastName");
                    homePhone     = rs.getString("HomePhone");
                    workPhone     = rs.getString("WorkPhone");
                    email         = rs.getString("Email");
                    city          = rs.getString("City");
                    provinceState = rs.getString("ProvinceState");
                    country       = rs.getString("Country");
                    zipPostalCode = rs.getString("ZipPostalCode");
                    unitNum       = rs.getString("UnitNum");
                    streetNum     = rs.getString("StreetNum");
                    streetName    = rs.getString("StreetName");
                    addressID     = rs.getString("AddressId");
            } catch (SQLException e) {
                e.printStackTrace();
            info.setCustomerID(customerID);
            info.setFirstName(firstName);
            info.setLastName(lastName);
            info.setHomePhone(homePhone);
            info.setWorkPhone(workPhone);
            info.setEmail(email);
            info.setCity(city);
            info.setProvinceState(provinceState);
            info.setCountry(country);
            info.setZipPostalCode(zipPostalCode);
            info.setUnitNum(unitNum);
            info.setStreetNum(streetNum);
            info.setStreetName(streetName);
            info.setAddressID(addressID);
        public static void addCustomer(CustomerInfo cust) {
            try {
                int id = -1;
                PreparedStatement pstmt = con.prepareStatement("INSERT INTO Address" +
                        "(UnitNum, StreetNum, StreetName, City, ProvinceState, Country," +
                        " ZipPostalCode) VALUES(?, ?, ?, ?, ?, ?, ?)");
                pstmt.setString(1, cust.getUnitNum());
                pstmt.setString(2, cust.getStreetNum());
                pstmt.setString(3, cust.getStreetName());
                pstmt.setString(4, cust.getCity());
                pstmt.setString(5, cust.getProvinceState());
                pstmt.setString(6, cust.getCountry());
                pstmt.setString(7, cust.getZipPostalCode());
                pstmt.executeUpdate();
                ResultSet rs = pstmt.getGeneratedKeys();
                rs.next();
                id = rs.getInt(1);
                pstmt = con.prepareStatement("INSERT INTO Customer" +
                        "(FirstName, LastName, HomePhone, WorkPhone, Email, AddressID)"
                        + "VALUES(?, ?, ?, ?, ?, ?)");
                pstmt.setString(1, cust.getFirstName());
                pstmt.setString(2, cust.getLastName());
                pstmt.setString(3, cust.getHomePhone());
                pstmt.setString(4, cust.getWorkPhone());
                pstmt.setString(5, cust.getEmail());
                pstmt.setInt(6, id);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
        public void setFirstName(String newName) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Customer"
                                              + " SET FirstName = ? WHERE CustomerID = ?");
                pstmt.setString(1, newName);
                pstmt.setString(2, customerID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            firstName = newName;
        public void setLastName(String newName) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Customer"
                                              + " SET LastName = ? WHERE CustomerID = ?");
                pstmt.setString(1, newName);
                pstmt.setString(2, customerID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            lastName = newName;
        public String getFirstName() {
            return firstName;
        public String getLastName() {
            return lastName;
        public void setHomePhone(String number) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Customer"
                                              + " SET HomePhone = ? WHERE CustomerID = ?");
                pstmt.setString(1, number);
                pstmt.setString(2, customerID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            homePhone = number;
        public String getHomePhone() {
            return homePhone;
        public void setWorkPhone(String number) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Customer"
                                              + " SET WorkPhone = ? WHERE CustomerID = ?");
                pstmt.setString(1, number);
                pstmt.setString(2, customerID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            workPhone = number;
        public String getWorkPhone() {
            return workPhone;
        public void setEmail(String email) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Customer" + " SET Email = ? WHERE CustomerID = ?");
                pstmt.setString(1, email);
                pstmt.setString(2, customerID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            this.email = email;
        public String getEmail() {
            return email;
        public void setUnitNum(String num) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Address" + " SET UnitNum = ? WHERE AddressId = ?");
                pstmt.setString(1, num);
                pstmt.setString(2, addressID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            unitNum = num;
        public String getUnitNum() {
            return unitNum;
        public void setCity(String city) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Address" + " SET City = ? WHERE AddressId = ?");
                pstmt.setString(1, city);
                pstmt.setString(2, addressID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            this.city = city;
        public String getCity() {
            return city;
        public void setStreetNum(String num) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Address" + " SET StreetNum = ? WHERE AddressId = ?");
                pstmt.setString(1, num);
                pstmt.setString(2, addressID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            streetNum = num;
        public String getStreetNum() {
            return streetNum;
        public void setStreetName(String name) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Address"
                                              + " SET StreetName = ? WHERE AddressId = ?");
                pstmt.setString(1, name);
                pstmt.setString(2, addressID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            streetName = name;
        public String getStreetName() {
            return streetName;
        public void setZipPostalCode(String code) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Address"
                                              + " SET ZipPostalCode = ? WHERE AddressId = ?");
                pstmt.setString(1, code);
                pstmt.setString(2, addressID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            zipPostalCode = code;
        public String getZipPostalCode() {
            return zipPostalCode;
        public CustomerInfo getInfo(){
            return info;
        static void deleteCustomer(String customerId) {
            try{
                PreparedStatement pstmt = con.prepareStatement("DELETE FROM Customer" +
                        " WHERE CustomerId = ?");
                pstmt.setString(1, customerId);
                pstmt.executeUpdate();
            }catch(SQLException e){
                e.printStackTrace();
        static void updateCustomer(CustomerInfo custInf) {
            try{
                PreparedStatement pstmt = con.prepareStatement("UPDATE customer" +
                        " SET firstName = ?, SET lastName = ?," +
                        " SET homePhone = ?, SET workPhone = ?, SET email = ?" +
                        " WHERE CustomerId = ?");
                pstmt.setString(1, custInf.getFirstName());
                pstmt.setString(2, custInf.getLastName());
                pstmt.setString(3, custInf.getHomePhone());
                pstmt.setString(4, custInf.getWorkPhone());
                pstmt.setString(5, custInf.getEmail());
                pstmt.setString(6, custInf.getCustomerID());
                pstmt.executeUpdate();
                pstmt = con.prepareStatement("UPDATE address" +
                        " SET unitNum = ?, SET StreetNum = ?, SET StreetName = ?," +
                        " SET city = ?,SET Province = ?,SET country = ?,SET ZipPostalCode = ?" +
                        " WHERE AddressId = ?");
                pstmt.setString(1, custInf.getUnitNum());
                pstmt.setString(2, custInf.getStreetNum());
                pstmt.setString(3, custInf.getStreetName());
                pstmt.setString(4, custInf.getCity());
                pstmt.setString(5, custInf.getProvinceState());
                pstmt.setString(6, custInf.getCountry());
                pstmt.setString(7, custInf.getZipPostalCode());
                pstmt.setString(8, custInf.getAddressID());
                pstmt.executeUpdate();
            }catch(SQLException e){
                e.printStackTrace();
    }In addition, here is my customer sql table.
    -- Table structure for table `customer`
    DROP TABLE IF EXISTS `customer`;
    CREATE TABLE `customer` (
    `CustomerID` mediumint(9) NOT NULL auto_increment,
    `FirstName` varchar(20) NOT NULL,
    `LastName` varchar(20) NOT NULL,
    `HomePhone` varchar(11) NOT NULL,
    `WorkPhone` varchar(11) default NULL,
    `Email` varchar(20) NOT NULL,
    `AddressID` mediumint(9) default NULL,
    PRIMARY KEY (`CustomerID`),
    KEY `AddressID` (`AddressID`),
    CONSTRAINT `customer_ibfk_1` FOREIGN KEY (`AddressID`) REFERENCES `address` (`AddressID`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    -- Dumping data for table `customer`
    LOCK TABLES `customer` WRITE;
    /*!40000 ALTER TABLE `customer` DISABLE KEYS */;
    /*!40000 ALTER TABLE `customer` ENABLE KEYS */;
    UNLOCK TABLES;

    to the best of my knowledge, this is something related to the database and not the programming. If you'd want to be the only user to read and edit the table, speicify only one user with that privilege and make it password protected. User must enter the password to write to the tables.

Maybe you are looking for

  • FIRST TIME RUNNING THE DEFAULT BSP APPLICATION IN ABAP

    Hi BSP experts,         I am happy to see many people are solving the problems on BSP in sdn. I am running the bsp application for the first time by taking the t-code se80 into consideration and executing the default bsp application given there.But I

  • ITunes 10.4 and windows XP not available

    I installed the las version of iTunes 10.4 and its not operate with windows XP SP3. When I start iTunes, after 30 seconds from the general pagesis displayed, the tipical message of windows appers. Windows has found a problem and must be close this ap

  • What is the best word processing program for mac?

    What is the best word processing program for Mac?

  • Leading Zeros in bank Account for EBS

    Hi, We configured the bank account number with two leading zeros in the house bank.  Say for example i defined the bank account number as 0012345 Under house bank HSBC. When I receive the bank statement, the bank account number is coming with 12 digi

  • Help Installing an older version of iTunes

    I recently installed iOS 7 on my iPhone 4s and -- because I was running iTunes 10.6 -- was required to install iTunes 11.1 With iTunes 11.1, I can't access the iTunes Store.  Whenever I try, the progress bar gets almost to the end and then iTunes cra