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.

Similar Messages

  • PC can read but a Apple can not VIA internet

    I have a G5 Tower with filemaker pro 5 on the LAN side of the network. I have mapped the IP address to the G5. In the router, a Linksys, I opened port #5003 & #591 for Filemaker and port #548 for Apple. On the LAN side of the network all my Macs and the 1 PC has no problem communicating with the G5 and Filemaker. But when I go to the Wan side and try to connect to the G5 VIA the internet from a remote location, the PC can read the Filemarker files on the G5 but not a MAC. Any Ideas what I need to do to the router so I can have Macs get the file VIA internet?
    The system does works with Macs and PC and can read filemaker VIA internet on a another router provided from another ISP provider. I want to go to a T1 line and purchased a Linksys route.
    This is what I have on the network from the T1 Line. Cisco 1700 and then it connects to a Netgear switching hub and from there it goes to the Linksys.

    There is a 3rd party app, AirParrot, that "mirrors" my screen to my HDTV via a new AppleTV.  http://www.airsquirrels.com/airparrot/
    They have Windows & OS X versions (OS X for the Macs older than mid-2011).

  • Two user profiles on my iMac but only one can connect to the internet

    Hi,
    I got the most recent upgrade for Lion and installed it.  I have two user profiles on my iMac and now, only one of them can connect to the internet yet both appear to have gotten the full upgrades.  Any ideas why this might be happening?
    Thanks!!

    Does the Account that can not connect to the Internet have full Administative priveleges or is it a Standard Account. If Standard, check to make sure it is allowed to connect.

  • Adobe Acrobat form can be opened in Adobe Reader but no one can fill it out. Why not?

    So I created a form for my job that my co-workers and clients need to be able to fill out. It was created in Acrobat and while others can open it in their Adobe Reader they are unable to edit any of the fields/fill the form out. Any ideas what might be causing this or what I might do to fix this?
    Thank you,
    Sara

    Hi There,
    So I found out where I'm running into the problem. The document works fine as long as I don't have a submit button included (something that is added via Acrobat) - if the submit button is removed and I save it - the document can be opened and edited in Reader. However, if it has the submit button, nothing works. Do you have any idea what would cause this disconnect between acrobat and reader? It makes no sense to have "add button" as a feature if it doesn't work outside of acrobat.
    Thanks,
    Sara

  • All users can send, but only Administrators can receive mail. How can I fix this?

    Been fighting with the email admin all day, why can I send and receive mail and my clients can only send?
    I discovered if I make them Server Administrators they can receive too! Both POP & IMAP only work for Admins, SMTP works for everyone. Non-Admins get a "bad user name or password" when they try to check their mail, even though they can log into the server desktop.
    Anyone got any ideas about this?
    Thanks!

    Hi Daniel,
    The access for mail might be restricted by service ACL, which you can find in server admin, select your server and go to Access on the top row to the far right. There services like mail might be restricted to administrators only and of course system administrators are most likely exempt.
    Turn the service access off and verify functionality with webmail for instance.
    Goodluck!
    Jeffrey

  • Hello guys. May you please help me with something? I have read something about "I can't Register my Debit Card". So, May someone explain me any other way to Purchase Apps? I can do it using Paypal? Thanks.

    Hello guys. May you please help me with something? I have read something about "I can't Register my Debit Card". So, May someone explain me any other way to Purchase Apps? I can do it using Paypal? Thanks.

    Read this:
    http://support.apple.com/kb/HT5552

  • My bookmarks have disappeared and I can't add new ones. can anyone help?

    my bookmarks have disappeared and I can't add new ones. can anyone help?

    Try a reset:
    Hold the Sleep and Home button down for about 10 second until you see the Apple logo.

  • I can read but I can't write to an external drive - changing permissions

    I can read but I can't write to an external drive. 
    How do I change permissions? None of the helps here on the discussions have helped.
    Why would a computer company let me read files but not write? Hahaha. This is insane.
    I have to write computer files for work. It's a project due this morning.
    Man, I'm going to have to go back to PC.
    Just need the compter to write files.

    If it's formatted as NTFS, reformat it as MS-DOS, exFAT, or Mac OS Extended (Journaled) as desired.
    If it's formatted as FAT32 or exFAT, use the Disk Utility's Repair Disk command on it.
    If it's formatted as Mac OS Extended, click Authenticate and provide your administrator password, or change the permissions on that specific folder in its Get Info window.
    (72460)

  • Help--How can I open only one java program at one time?

    How can I open only one java program(same program) in Windows at one time?

    In Java 1.5, you can use the JVM's own monitoring APIs to examine what other JVMs are running on the system, and what applications they're running.
    It's general and powerful, but complex. The socket/file/whatever approach is cleaner, and probably more suited to your usage.
    Don't bother trying to use the Windows task manager for this sort of thing. You have to write messy native code, and it isn't reliable after all that anyway.

  • Hi...I have 4 folders in my MobileMe Gallery.....but only one is shown in Aperture under WEB. Anybody who can help? best, Per

    Hi...I have 4 folders in my MobileMe Gallery.....but only one is shown in Aperture under WEB. Anybody who can help? best, Per

    Hello Per,
    did you create the other Mobile Me galleries in iPhoto? If I remember correctly. you can manage each web album only in one application, either Aperture or iPhoto. I cannot test it any longer, since I upgraded to iCloud, but it used to be possible to assign the application (iPhoto or Aperture) for each album when you log into Mobile Me and select the album.
    Regards
    Léonie

  • My mac can't connect to belkin router?  My mac can connect but I still can't surf the net? Help Please... This is my first time to use mac and belkin.

    My mac can't connect to belkin router?  My mac can connect but I still can't surf the net? Help Please... This is my first time to use mac and belkin.

    Is it Wireless you're trying to connect with?
    Which Mac?
    So we know more about it...
    At the Apple Icon at top left>About this Mac, then click on More Info, then click on Hardware> and report this upto but not including the Serial#...
    Hardware Overview:
    Model Name: iMac
    Model Identifier: iMac7,1
    Processor Name: Intel Core 2 Duo
    Processor Speed: 2.4 GHz
    Number Of Processors: 1
    Total Number Of Cores: 2
    L2 Cache: 4 MB
    Memory: 6 GB
    Bus Speed: 800 MHz
    Boot ROM Version: IM71.007A.B03
    SMC Version (system): 1.21f4

  • TS1292 When I scratched the code, the letters came off with. I can read two X, one Z, S, R, and N, the rest are illegible

    When I scratched the code the letters came off with. I can read two X, one Z, S, R, and N, the rest are illegible

    Try here  >   iTunes Store: Invalid, inactive, or illegible codes

  • HT3430 Why isn't there at least a reader so that one can read the new format? Microsoft at least does that.

    Why isn't there at least a reader so that one can read the new format? Microsoft at least does that.

    Preview opening Pages documents is a Lion/Mountain Lion feature but QuickLook works well.
    You can even flick through the individual pages of the document.
    Peter

  • How can I delete only one part of my xml file?

    Hello,
    I stored more than 100 users in only one xmltype column. For instance
    Create table agro(users XMLTYPE);
    ... and I inserted all users inside
    INSERT INTO agro values(XMLTYPE
    ('<?xml version="1.0" encoding="ISO-8859-1"?>
    <authentication><users><user>
    <name>cocoon</name>
    <password>cocoon</password>
    <role>admin</role>
    <title>Mr.</title>
    <firstname>Walter</firstname>
    <lastname>Cocoon</lastname>
    <company />
    <street />
    <zipcode />
    <city />
    <country>DE</country>
    <phone />
    <fax />
    <email />
    <bankid />
    <bankname />
    <accountid />
    </user>
    ... another user, etc.
    </users></authentication>'));
    Now I tried to delete only one part of this file. For example all persons with the name"cocoon".
    I used for this target the following statement:
    DELETE FROM agro agro
    WHERE agro.users.extract('authentication/users/user/text()').getStringVal()= 'cocoon';
    When I execute this statement, Oracle DB delete all users and not only with the name "Cocoon".
    How can I delete only one part of my xml file?
    Kind Regards
    M R

    This the expected behavoir. You uploaded a document containing multiple users and then asked XML DB to delete any documnet that contained a user with the name in question. The problem here is that you are creating a mega document that contains an aggregation of user documents but then trying to work with individual user documents. This is a bad idea.
    In general XML does not understand the concept of a collection of documents. It can only operate on one document at a time. Hence the tendancy to aggregate individual documents into a single larger document. Once you have an XML database, you can perform operations on collections of document, as easily as you can perform operations on individual documents, so the need to aggregate the individual documents together disappears.
    If you store each user document as a seperate document then your delete will work as expected.

  • Listview checkbox group item only one can be checked

    I have a listview with checkbox , and grouped some checkbox, I need only can be checked for two checkboxes, but I use
     private void Listview_ItemCheck(object sender, ItemCheckEventArgs e)
                this.Listview.Items[0].Checked = !this.Paramlst2.Items[1].Checked;
                this.Listview.Items[1].Checked = !this.Paramlst2.Items[0].Checked;
    but it is not worked.
    can anybody suggest me how to modify the code to realize item0 and item1 only one can be checked.
    thanks

    Hi Sunny,
    According to your title, do you mean you only one checkbox is required to check?
    And the code, it seems not clear to me. What is Paramlst2 stand for?Which control did you use ?
    Could you help provide more information? It would be better to help us to understand your issue.
    Have a nice day!
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for