Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: hello everyone i'm new i have a problem with some small project i'm trying to do

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default hello everyone i'm new i have a problem with some small project i'm trying to do

    I'm trying to enter data into two different tables with the same form, but i seem to have an error most probably with data types
    the method below is supposed to enter data into two mysql tables namely employees and login
    the data types for the fields in the employee table are as follows
    id -int
    firstname - text
    middlename -text
    lastname - text
    date_of_birth -date
    age - int
    wage - double

    the data types for the mysql login table are as follows
    id - int
    username - text
    password - text
    times late - int
    hours worked - time

    private void txtsaveActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    try{
    connection();
    String id = txtid.getText();
    String first = txtfirst.getText();
    String middle = txtmiddle.getText();
    String last = txtlast.getText();
    String date = txtdob.getText();
    String age = txtage.getText();
    String user = txtuser.getText();
    String pass = txtpass.getText();
    String late = txtlate.getText();
    String hours = txthours.getText();
    String wage = txtwage.getText();
    double wages = Double.parseDouble(wage);
    int iden = Integer.parseInt(id);
    int old = Integer.parseInt(age);
    DateFormat sdf = new SimpleDateFormat("yyyy/mm/dd/");
    Date dates = sdf.parse(date);
    DateFormat how = new SimpleDateFormat("hh:mm:ss");
    Date here = how.parse(hours);
    int latenom = Integer.parseInt(late);
    stm.executeUpdate("INSERT INTO employees(ID,Firstname,Middlename,Lastname,Date_Of _Birth,Age,Wage)values('"+iden+ "','"+first+"','"+middle+"', '"+last+"', '"+dates+"','"+old+"','"+wages+"')");

    JOptionPane.showMessageDialog(null, "Information successfully added to database");
    }
    catch(Exception hy){
    JOptionPane.showMessageDialog(null, "Error Detected");
    }


    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,577
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: hello everyone i'm new i have a problem with some small project i'm trying to do

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    i seem to have an error
    Please copy the full text of the error message and paste it here. It has important info about the error.

    Also add a call to the printStackTrace() method to the catch block to see what the error is.
    Last edited by Norm; August 6th, 2014 at 01:20 PM. Reason: Fixed spelling
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,290
    My Mood
    Mellow
    Thanks
    191
    Thanked 668 Times in 655 Posts

    Default Re: hello everyone i'm new i have a problem with some small project i'm trying to do

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

  4. #4
    Junior Member
    Join Date
    Jul 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem adding data to two mysql tables via a jframe form

    I'm tyring to create a form whic will enter data into two different mysql tables namely login and employees.
    Below are the datatypes for each field in these two tables

    employee table
    id - integer
    firstname - text
    middlename - text
    lastname - text
    date of birth - date
    age - integer
    wage - double

    login table
    id -integer
    username - text
    password - text
    number of times late - integer
    hours worked - time

    below is the method


    private void txtsaveActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    try{
    connection();
    String id = txtid.getText();
    String first = txtfirst.getText();
    String middle = txtmiddle.getText();
    String last = txtlast.getText();
    String date = txtdob.getText();
    String age = txtage.getText();
    String user = txtuser.getText();
    String pass = txtpass.getText();
    String late = txtlate.getText();
    String hours = txthours.getText();
    String wage = txtwage.getText();
    double wages = Double.parseDouble(wage);
    int iden = Integer.parseInt(id);
    int old = Integer.parseInt(age);
    DateFormat sdf = new SimpleDateFormat("yyyy/mm/dd/");
    Date dates = sdf.parse(date);
    DateFormat how = new SimpleDateFormat("hh:mm:ss");
    Date here = how.parse(hours);
    int latenom = Integer.parseInt(late);
    stm.executeUpdate("INSERT INTO employees(ID,Firstname,Middlename,Lastname,Date_Of _Birth,Age,Wage)values('"+iden+ "','"+first+"','"+middle+"', '"+last+"', '"+dates+"','"+old+"','"+wages+"')");

    JOptionPane.showMessageDialog(null, "Information successfully added to database");
    }
    catch(Exception hy){
    JOptionPane.showMessageDialog(null, "Error Detected");
    }


    }

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,577
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: hello everyone i'm new i have a problem with some small project i'm trying to do

    Duplicate threads merged.

    See post#2
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Jul 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: hello everyone i'm new i have a problem with some small project i'm trying to do

    it says error message error detected.
    tried adding a call to the printStaclTrace() method but got an error

  7. #7
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: hello everyone i'm new i have a problem with some small project i'm trying to do

    The method name is printStackTrace. Typo by Norm.
    Improving the world one idiot at a time!

Similar Threads

  1. Small project for my own experience...
    By Padmahasa in forum Paid Java Projects
    Replies: 2
    Last Post: January 27th, 2013, 07:31 AM
  2. Help with small java project
    By vlond147 in forum Paid Java Projects
    Replies: 3
    Last Post: January 5th, 2013, 10:29 AM
  3. NullPointerException in a small project
    By Samaras in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 9th, 2012, 11:00 AM
  4. Small Project
    By 3XiLED in forum Paid Java Projects
    Replies: 7
    Last Post: March 1st, 2010, 07:35 AM