Terminal & MySQL Syntax

I am a total newbie in using terminal. I installed MAMP and am trying to find my way around through a php/mysql tutorial.
Issue: I can get my Terminal prompt to show as mysql> but however I try to type in commands (as per the tutorial) I keep getting a new line with and arrow ( -> ).
Can you point me in the right direction?
Thanks.

It is waiting for you to finish the command. Until you end the command line, it keeps waiting for you to add more to the command. If it is like other SQL, then end the command with a semi-colon (;)

Similar Messages

  • Learn Terminal, MySQL, PHP

    I am looking for someone in the Tampa area to show me how to access and use Terminal, MySQL and PHP on my Macs. I am getting ready to take some online classes in MySQL and PHP and need to have those programs up and running on my Macs. I am willing to pay someone for tutoring.
    Thanks,
    JJ

    Thanks for your reply. I do understand that he education I receive would be applicable to the Mac, but my roblem is that I do not know how to use Terminal, and how to see whether o not I have PHP and MySQL installed properly on my machines. What's more, how to access these programs.
    THanks.

  • Error when creating a description field. MySQL syntax to use?

    I'm creating a form which has a description field in it. I created this form with many fields. However I then got an error and decided to limit the form to only 2 fields. These 2 fields (user and title) insert with no problem. However when I added the description field into the mix. I gat the same error I had previously gotten.
    Error:
    Internal error.
    Developer Details:
    tNG_fields.getFakeRecordset:
    SQL error: Error creating temporary table:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc TEXT, job_id TEXT)' at line 1
    SQL:
    CREATE TEMPORARY TABLE KT_fakeRS_20080204 (client_id TEXT, name TEXT, desc TEXT, job_id TEXT) (FIELDS_FAKE_RS_ERROR)
    tNG Execution Trace - VIEW
    * tNG_insert.executeTransaction
    o STARTER.Trigger_Default_Starter
    * tNG_insert.getRecordset
    * tNG_insert.getLocalRecordset
    * tNG_insert.getFakeRecordset*
    I'm using the "Text" syntax for the field "desc" (description)
    What am I doing wrong? Do I need to define the table row in a different way?

    Hi,
    I am working on an image gallery using the tutorials.
    I used the sql
    SELECT *,
    rand() as random_number
    FROM image_img
    ORDER BY random_number DESC LIMIT 1
    on my default.php page but on preview i get the message
    You have an error in your SQL syntax near 'LIMIT 0, 10' at line 1
    I tried the solution above by removing the desc limit.
    I got the same prob.
    I will like to know how best to tackle this.
    Thanks
    Yomi

  • MySQL syntax error with TestStand 4.0 database logging

    I had been using MS Access database to log results which worked fine but the access database is too limited. Switched to MySql. Database works fine and I can query it from Visual C++ and was able to create all my result tables fine from TestStand.
    I get a syntax error when actually trying to log results and it has to do with either a missing quote or and extra quote, I can't quite tell. I thought I saw a post on this somewhere but can't find it now. Here is the complaint from TestStand:
    An error occurred calling 'LogOneResult' in 'ITSDBLog' of 'zNI TestStand Database Logging'
    An error occurred executing a statement.
    Statement: UUT_RESULT.
    [MySQL][ODBC 3.51 Driver][mysqld-5.0.45-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFAULT VALUES' at line 1
    Description: [MySQL][ODBC 3.51 Driver][mysqld-5.0.45-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFAULT VALUES' at line 1
    Number: -2147467259
    NativeError: 1064
    SQLState: 37000
    Reported by: Microsoft OLE DB Provider for ODBC Drivers
    Description: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
    Number: -2147217887
    NativeError: 0
    SQLState: 37000
    Reported by: Microsoft OLE DB Provider for ODBC Drivers
    Source: TSDBLog
    And here is all that appears in the MySql logfile:
    INSERT INTO UUT_RESULT DEFAULT VALUES
    070914
    You can't see it here but the string is truncated after the word VALUES. The next line starts with the odd number.
    Any ideas?
    Thanks,
    Bill Peters
    BAE SYSTEMS

    Sure. There were two bugs in the ini file that contains the default TS schemas (I think it was Default_Database_Options.ini or like that...).
    Anyway the table description for STEP_NUMERICLIMIT had for it's command line INSERT INTO MEAS_NUMERICLIMIT. I guess TestStand looked at that and said hmm I better create that table too. Then later down the page when you try to create MEAS_NUMERICLIMIT it says the table already exists even though it is empty. The generate SQL button builds a bad file and then the database viewer creates a bad database. I would have to go into MySql and drop the database. I had to save the schema under a custom name, edit it read it back in, generate a new SQL file, but then it would still fail validation because the ini files don't get updated until you exit TestStand. So basically I did this process 3 times before I got it right.
    It's wasn't a big deal but it's amazing how a little thing can cause a lot of work.
    The second bug, I'm not certain was initially in the file or somehow got set on the fly. There was a random int statement at the very end of the SQL table description for UUT_RESULT. It was also in the schema INI file. Since the int had no name and occurred in a odd place, it created a syntax error in MySql. Same fix as above.
    But like I said it's working great now. I like this approach because I serve it to the net with Apache and parse the database with simple PHP scripts.
    Thanks,
    Bill Peters
    BAE SYSTEMS

  • Terminal/mysql screwup - internet not working now!

    I was working in Terminal trying to setup mysql on my g4 powerbook to get Wordpress to work, but someone quit my session of Terminal in the middle of it. Now the internet will not connect. I am using a simple eternet connection. Can someone help me get this back to normal (I won't worry about intalling Wordpress right now. Here is what my Terminal history looks like:
    Welcome to Darwin!
    PowerBook:~ Powerbook$ history
    1 cd /usr/local/mysql
    2 sudo chown -R mysql data/
    3 sudo echo
    4 sudo ./bin/mysqld_safe &
    5 /usr/local/mysql/bin/mysql test
    6 /usr/local/mysql/bin/mysql -u root -p
    7 /usr/local/mysql/bin/mysql test
    8 sudo pico /etc/httpd/httpd.conf
    9 mysql
    10 quit
    11 pkgrm PACKAGE_NAME
    12 pkginfo
    13 cd /usr/local
    14 sudo rm mysql
    15 sudo rm -rf mysql-3.23.47-apple-darwin5.1-p
    16 history
    PowerBook:~ Powerbook$

    Hi again Robert! Glad you found your way here.
    It could be that step 8: sudo pico /etc/httpd/httpd.conf, is the cause of your problem. Did you save the original file first? Is there a backup file in that directory (either httpd.conf~ or httpd.conf.bak)?
    Do you have a httpd.conf.default in there? I do, but may have created it myself.
    Also, step 4 created a background process that may still be running. I don't know how that would affect things. Maybe someone with MySQL knowledge can chip in.
    Anyway, I'm sure you'll find an answer now you're posting in the right place

  • Find Duplicate Query MySQL Syntax

    There is a "find duplicates" query in SQL that is very useful
    but I'm not sure what the syntax is for MySQL. It probably has
    something to do with select distinct, group by but I'm not used to
    to using these.
    This is one that finds all duplicates of [FULLNAME]
    SELECT CONTACTS.*
    WHERE (((CONTACTS.FULLNAME) In (SELECT [FULLNAME] FROM
    [CONTACTS] As Tmp GROUP BY [FULLNAME]
    HAVING Count(*)>1 )))
    ORDER BY CONTACTS.FULLNAME, CONTACTS.COMPANY
    Does anyone know?

    RichardODreamweaver wrote:
    > There is a "find duplicates" query in SQL that is very
    useful but I'm not sure
    > what the syntax is for MySQL.
    SELECT COUNT(*) AS repetitions, FULLNAME, COMPANY
    FROM CONTACTS
    GROUP BY FULLNAME, COMPANY
    HAVING repetitions > 1
    It's not something I have used myself, but I got it from
    MySQL Cookbook
    by Paul DuBois, published by O'Reilly. I have the first
    edition, which
    covers MySQL 4.0. I think the second edition covers MySQL
    5.0.
    If you're using MySQL on a regular basis, you or your
    employer should
    buy it immediately. It will solve most of your problems and
    repay its
    cost many times over.
    David Powers, Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • Mysql syntax error

    Hi, I am trying to run the following query with JDBC. It works perfectly when done through a normal mysql admin tool but not with JDBC
    Apparently the error is on the last line. Do you guys know why?
    Cheers.
    CREATE TABLE archive (   ar_namespace int(11) NOT NULL default '0',   ar_title varchar(255)  NOT NULL default '',   ar_text mediumblob NOT NULL,   ar_comment tinyblob NOT NULL,   ar_user int(10) unsigned NOT NULL default '0',   ar_user_text varchar(255)  NOT NULL,   ar_timestamp binary(14) NOT NULL default '\0\0\0\0\0\0\0\0\0\0\0\0\0\0',   ar_minor_edit tinyint(4) NOT NULL default '0',   ar_flags tinyblob NOT NULL,   ar_rev_id int(10) unsigned default NULL,   ar_text_id int(10) unsigned default NULL,   ar_deleted tinyint(3) unsigned NOT NULL default '0',   ar_len int(10) unsigned default NULL,   ar_page_id int(10) unsigned default NULL,   KEY name_title_timestamp (ar_namespace,ar_title,ar_timestamp),   KEY usertext_timestamp (ar_user_text,ar_timestamp));

    Hey thanks.
    It did work for the first query but broke the following. I am trying to query all of the following:
    CREATE TABLE archive (
      ar_namespace int(11) NOT NULL default '0',
      ar_title varchar(255)  NOT NULL default '',
      ar_text mediumblob NOT NULL,
      ar_comment tinyblob NOT NULL,
      ar_user int(10) unsigned NOT NULL default '0',
      ar_user_text varchar(255)  NOT NULL,
      ar_timestamp binary(14) NOT NULL default '\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0',
      ar_minor_edit tinyint(4) NOT NULL default '0',
      ar_flags tinyblob NOT NULL,
      ar_rev_id int(10) unsigned default NULL,
      ar_text_id int(10) unsigned default NULL,
      ar_deleted tinyint(3) unsigned NOT NULL default '0',
      ar_len int(10) unsigned default NULL,
      ar_page_id int(10) unsigned default NULL,
      KEY name_title_timestamp (ar_namespace,ar_title,ar_timestamp),
      KEY usertext_timestamp (ar_user_text,ar_timestamp))
    # Dump of table categorylinks
    #DROP TABLE IF EXISTS categorylinks
    CREATE TABLE categorylinks (
      cl_from int(10) unsigned NOT NULL default '0',
      cl_to varchar(255)  NOT NULL default '',
      cl_sortkey varchar(70)  NOT NULL default '',
      cl_timestamp timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
      UNIQUE KEY cl_from (cl_from,cl_to),
      KEY cl_sortkey (cl_to,cl_sortkey,cl_from),
      KEY cl_timestamp (cl_to,cl_timestamp)
    # Dump of table externallinks
    #DROP TABLE IF EXISTS externallinks
    CREATE TABLE externallinks (
      el_from int(10) unsigned NOT NULL default '0',
      el_to blob NOT NULL,
      el_index blob NOT NULL,
      KEY el_from (el_from,el_to(40)),
      KEY el_to (el_to(60),el_from),
      KEY el_index (el_index(60))
    ) New error:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE categorylinks (
      cl_from int(10) unsigned NOT NULL default '0',
      ' at line 40It breaks at the line: CREATE TABLE categorylinks (
    Any ideas why?
    Cheers

  • Terminal & mysql

    I have the GUI tools for mysql and have no problem creating and accessing databases through these tools, but I am unable to do anything with mysql through the terminal window.
    As a novice with the terminal and unix were should I start as no mysql command works at all.
    Thanks

    I use mysql from terminal all the time. Normally, it is installed into "/usr/local/bin", but that directory is not in your default path. I have a ".bashrc" file in my home directory that has the following:
    if [ -d "/usr/local/sbin" ]; then
    export PATH="/usr/local/sbin:${PATH}"
    fi
    if [ -d "/usr/local/bin" ]; then
    export PATH="/usr/local/bin:${PATH}"
    fi
    Generally, you want the /usr/local directories first and those statements do it. This will make it work everytime that you start up Terminal. As an experiment, just enter the export commands when you start up terminal and then try the mysql command below.
    If that is not your problem, but you can't start mysql. You use:
    mysql -p -u xyzzy<return>
    where xyzzy is your mysql user name. Then you will be prompted for your mysql password. Assuming you logged on, you can enter the sql commands from there. Make you that you end each one with a ';'. Also,'quit;' gets you out of mysql.
    By your description, I wasn't exactly sure what your problem is. If it is neither above, could you give me more details? Like error messages or a transcript of your interaction with mysql.
    Terminal has a handy feature. You use AppleKey+k to clear the terminal screen/log. Then enter your commands. Then use the terminal menu, File->Save Text as..., to save the terminal log as text to a file. If it is not too long, then you can post it in a message here.
    HTH
    Disregard the lines being drawn through '-d "/usr/local/..."', it must be a formatting command to the discussion group somehow. Just use the stuff behind it.
    Message was edited by: Bob White

  • MySQl syntax error near " at line 1 and Unknown column. Please help

    Hello again,
    I have another question. Just to refresh I am using DWCS3 with MAMP on my MBP Leopard 10.5.6.
    I have created a form with the form wizard and a Transitional <!DOCTYPE>
    I have added the php validation code pages 481 to 485 The Essential Guide to Dreamweaver.
    I saved it and uploaded it to the testing server clicked the "insert form" button,and  I got;
    You have an error in your SQL syntax; Check the manual that corresponds to your MySQL server version for the right syntax to use near " at line 1
    The MySQL version I am using is 5.0.37. I have gone over and over the code and I can't find what is wrong with it.
    Also for the username column, I am now getting a message;
    'Unknown column'  'ella1' in 'where clause'
    I have researched it on the web and possible answers are that my columns are misspelled, the column doesn't exist or username is not in the query.
    I have checked all of these and I really can't see the problem, but there obviously is one.
    Please can someone help.
    Thanks again.
    P.S. I have attached the page in a .zip file if anyone wouldn't mind having a look.

    No, I'm talking about the dot before.
    Change this
    .$row_detailsRS[$details_prodID] . "";
    to this
    . $row_detailsRS[$details_prodID] . "";
    in both places.

  • JDBC/MySQL syntax error on MySQL server login

    I am making a simple JSP page and I'm trying to test basic functionality/connectivity with a MySQL database. Included is my index.jsp code and the errors given by Tomcat. Any insights would be very helpful, thanks.
    org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 13 <%@ page import="java.sql.*"%> <% Connection con = null; Statement stmt = null; ResultSet rs = null; %> <html> <body> <% Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/database", "correctUserName", "correctPassword");    //<-line 13 stmt = con.createStatement(); rs = stmt.executeQuery("SELECT * FROM table"); while(rs.next()){ out.println(rs.getString("name")+"<br>"); } rs.close(); %> </body </html> Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) root cause javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '????????????????' at line 1 org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791) org.apache.jsp.index_jsp._jspService(index_jsp.java:86) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    chrislard wrote:
    That is a good idea for actual implementation, but this is just a test. There isn't any reason that this should not work because it hasn't been broken up into multiple files etc.Evidence would indicate that it is not in fact working though. And the error indicates a syntax error. Because it is JSP there is no assured way to localize the problem, not to mention that since it is running is a container there is no assurance that the posted code is even what is running.
    My suggestion on the other hand completely eliminates all of those possibilities.
    But if it helps you the posted SQL does not have any syntax errors. So if you can solve the problem that you have knowing just that then go for it. Myself I would at least create a test jig.

  • Mysql syntax in java help please!!

    the below code works nice, but how do i place a variable in the VALUES part of the recordsUpdated statement. I can only place in numbers or letters but not variables. Lets say i want to loop this 20 times and i want it to write to the table 20 times, each time, the number int the VALUES increments (p++) where p is the variable. How do i place the varible in the sql statement? is that possible? or is there even a way?
    for(p = 100; p<120; p++)
    recordsUpdated = stmt.executeUpdate("INSERT INTO users (userid, usernum) VALUES(344, 452)");
      rs = stmt.executeQuery("SELECT userid, usernum FROM users");
          }thanks for any help!! =)

    Try
    String sql="INSERT INTO users (userid, usernum) VALUES(?, ?)";
    PreparedStatement pmt = databaseConnection.prepareStatement(sql);
    for(int i = 0; i < 20; i++) {
              pmt.setInt(1, firstVar);
              pmt.setString(2, secondVar);
              pmt.executeUpdate();
    See at Java API for more information about prepared statements.

  • Problem with GRANT syntax in MYSQL statement...need help!

    Good afternoon all!
    I need a little help with some mysql syntax. I'm using version 4.0.17, and I'm just starting to try to learn about connection pooling (you'll probably see future posts from me on this topic as well:)...
    I'm following the directions contained on Apache's website (http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html) on how to set up a JNDI datasource.....
    The directions are simple, Create a new test user, a new database and a single test table. Your MySQL user must have a password assigned. The driver will fail if you try to connect with an empty password.
    I then proceed to enter this line into my mysql prompt - mysql> GRANT ALL PRIVILEGES ON *.* TO javauser@localhost IDENTIFIED BY 'javadude' WITH GRANT OPTION;
    Here's the error I get : ERROR 1045: Access denied for user: '@localhost' (Using password: NO)
    Can someone give me the heads up on what the "correct" syntax is?

    tnguyen1973 , I tried your statement again, this time excluding the -p, pressed Enter and then entered the statement I first posted, and it took that too.
    So I'm hoping I can now continue with the example provided on the Apache website.
    Can you tell me the difference between using the -p in the statement, and where I can learn more about these things?
    Thanks.

  • Make a carbon copy of your drive/folder with Terminal!

    I always see people throwing carbon copy disk programs around like no tomorrow. I've wondered to myself "why?". The termainl in Mac OSX can do it out of the box and do it for free and, for more advanced users, you can start getting rather fancy with the commands for fine tuning. Type man cp in the terminal for more info.
    Say I want to make a carbon copy of my Home folder to my external disk called "Backup USB" so I can restore it later to a new drive.
    Firstly, open Terminal.app found in Applications > Utilities. Make sure the External Disk is plugged in first before continuing.
    Now I simply type in the following command:
    cp -pvR /Users/benanderson "/Volumes/Backup USB/benanderson"
    Once typed, press the return key and let the computer do its job.
    I'll run through the command so people know what each section does
    cp: this is the command for "copy"
    -pvR: these are "flags" and tell the computer how to perform the action.
    p: this flag stands for "preserve" and keeps all the file attributes intact. A file or folders owner, group, permissions and time stamp will remain the same. Say I have a file in the finder with a "created" and "modified" date of 8th September 2011 (you can see these by single clicking a file an pressing cmd+i) - if I was to copy this with the finder, the created and modified date of the copy would change to 17th December 2011 (today). By specifying the -p flag, the copy will keep the 8th of September creation and modify date. This is very important for system files that MacOSX has to keep track of.
    v: verbose, it basically tells you what file is currently copying so you're not copying blind wondering what its doing and when it will finish. Its a progress bar, basically.
    R: it will mimic the directory structure of the folder you are copying. without the -R flag, if you ask cp to copy a folder, it will skip the folder because the folder is not a file. With -R, it will copy the folder, the files in the folder and any folders within the folder and so on.
    /Users/benanderson: this is my home folder. Your name will vary, obviously.
    "/Volumes/Backup USB/benanderson": The destination of the copy on the disk "Backup USB". I need double quotes around the destination because "Backup USB" as a space in it. Without the quotes, the computer would read it as "/Volumes/Backup" and stop there, which is invalid and would cause an error, stopping the copy from working.
    To restore from backup, just do it again in reverse order.
    cp -pvR "/Volumes/Backup USB/benanderson" /Volumes/benanderson
    Hit return and set it on its way!
    If you're feeling sassy, make a carbon copy of your Macintosh HD onto another HDD, a carbon copy of your home folder from your desktop computer onto your laptop computer over the network (I do this with my iTunes folder every few months), carbon copy your HDD onto a Disk Image so you can "flash" other HDDs from disk utility. Carbon copy of your time machine or time capsule if moving to a larger disk. The cp command is increadibly useful, free, easy and powerful - its most likely what the Carbon Copy programs are doing under the hood, so why not cut out the middle man?
    Just a nice tip for everyone interested!

    Carbon Copy Cloner is free; its tasks are editable and restrictable; it works via a simple user interface; and it works without error. There is next to no learning curve involved, no need to learn Terminal's syntax, and none of the dangers that an error in syntax can cause when using Terminal.
    Did I mention CCC is free?

  • 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.

  • Executing mysql script file in java

    Hello,
    I am working on a research project that involves the creation of anywhere from 50 to 200 MySQL databases at a time. So far I am able to execute CREATE DATABASE commands successfully using the Statement.execute() command.
    So onto my problem.....
    I have the script files needed to create the tables for each database, but I cannot figure out how to run them through java. I am trying to execute a SOURCE /file_location/ statement, but I am getting "you have an error in your mysql syntax....".
    Does anyone know if there is a way to execute a script file from java?

    You mean to say that you have websphear application server (WAS) installed on Windows NT machine. Can you please share how you have deployed your application on WAS. The problem might be just because of configuration. What error/exception you are getting when you run application in WAS.

Maybe you are looking for