Add data to the table in the database with the use of add button

The name of my database is Socrates.
The name of the table in the database is Employees
I want to be able to add data to the database. i am presently working on the add button such that when i enter date into the textfield and press the add button it should automatically register in the table.
The error upon compilation is with this line of code
If (ae.getSource() == jbtnA)// it says that ";" is expected
Below is the entire code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Mainpage extends JFrame implements ActionListener
     JTextField jFirstName = new JTextField(15);
     JTextField jSurname = new JTextField(12);
     JTextField jCity = new JTextField(10);
     JTextField jCountry = new JTextField(12);
     JTextField jSSN = new JTextField(8);
     JLabel jFirstLab = new JLabel("First Name");
     JLabel jSurnameLab = new JLabel("Surname");
     JLabel jCityLab = new JLabel("City");
     JLabel jCountryLab = new JLabel("Country");
     JLabel jSSNLab = new JLabel("Social Security Number (SSN)");
     JButton jbtnA = new JButton ("Add");
     JButton jbtnPrv = new JButton ("Previous");
     JButton jbtnNt = new JButton ("Next");
     JButton jbtnDl= new JButton ("Delete");
     JButton jbtnSrch = new JButton ("Search");
     public Mainpage (String title)
          super (title);
          Container cont = getContentPane();
          JPanel pane1 = new JPanel();
          JPanel pane2 = new JPanel();
          JPanel pane3 = new JPanel();
          pane1.setLayout (new GridLayout (0,1));
          pane2.setLayout (new GridLayout(0,1));
          pane3.setLayout (new FlowLayout());
          pane1.add(jFirstLab);
          pane1.add(jSurnameLab);     
          pane1.add(jCityLab);
          pane1.add(jCountryLab);
          pane1.add(jSSNLab);
          pane2.add(jFirstName);
          pane2.add(jSurname);
          pane2.add(jCity);
          pane2.add(jCountry);
          pane2.add(jSSN);
          pane3.add(jbtnA);
          pane3.add(jbtnPrv);
          pane3.add(jbtnNt);
          pane3.add(jbtnDl);
          pane3.add(jbtnSrch);
          cont.add(pane1, BorderLayout.CENTER);
          cont.add(pane2, BorderLayout.LINE_END);
          cont.add(pane3, BorderLayout.SOUTH);
          jFirstName.addActionListener(this);
          jSurname.addActionListener(this);
          jCity.addActionListener(this);
          jCountry.addActionListener(this);
          jSSN.addActionListener(this);
          jbtnA.addActionListener(this);
          jbtnPrv.addActionListener(this);
          jbtnNt.addActionListener(this);
          jbtnDl.addActionListener(this);
          jbtnSrch.addActionListener(this);
          validate();
          setVisible(true);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          pack();
          setResizable(false);
     public void actionPerformed(ActionEvent ae)
               If (ae.getSource() == jbtnA)
                                fst = jFirstName.getText();
                    srn = jSurname.getText();
                    cty = jCity.getText();
                    cnty = jCountry.getText();
                    int sn =
Interger.parseInt(jSSN.getText());
                                String ad = "Insert into Employees
(Firstname,Surname,City,Country,SSN)" +
"values('"fst"','"srn"','"cty"','"cnty"','"sn"')";
                    Statement stmt = con.createStatment();
                    int rowcount = stmt.executeUpdate(ad);
                    JOptionPane.showMessageDialog("Your
details have been registered");
                    Statement stmt = con.createStatment();
                    int rowcount = stmt.executeUpdate(ad);
public static void main (String args[])
          Mainpage ObjFr = new Mainpage("Please fill this
registration form");
          try
               Class.forname("sun.jdbc.odbc.JdbcOdbcDriver");
               String plato = "jdbc:odbc:socrates";
               Connection con =
DriverManager.getConnection(plato);
          catch(SQLException ce)
               System.out.println(ce);
}

i have restructured the code, but the following line of code is giving error:
String plato = jdbc:odbc:socrates;
the entire code is below:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class Mainpage extends JFrame implements ActionListener
     JTextField jFirstName = new JTextField(15);
     JTextField jSurname = new JTextField(12);
     JTextField jCity = new JTextField(10);
     JTextField jCountry = new JTextField(12);
     JTextField jSSN = new JTextField(8);
     JLabel jFirstLab = new JLabel("First Name");
     JLabel jSurnameLab = new JLabel("Surname");
     JLabel jCityLab = new JLabel("City");
     JLabel jCountryLab = new JLabel("Country");
     JLabel jSSNLab = new JLabel("Social Security Number (SSN)");
     JButton jbtnA = new JButton ("Add");
     JButton jbtnPrv = new JButton ("Previous");
     JButton jbtnNt = new JButton ("Next");
     JButton jbtnDl= new JButton ("Delete");
     JButton jbtnSrch = new JButton ("Search");
     Statement stmt;
        String ad;
        public Mainpage (String title)
          super (title);
          Container cont = getContentPane();
          JPanel pane1 = new JPanel();
          JPanel pane2 = new JPanel();
          JPanel pane3 = new JPanel();
          pane1.setLayout (new GridLayout (0,1));
          pane2.setLayout (new GridLayout(0,1));
          pane3.setLayout (new FlowLayout());
          pane1.add(jFirstLab);
          pane1.add(jSurnameLab);     
          pane1.add(jCityLab);
          pane1.add(jCountryLab);
          pane1.add(jSSNLab);
          pane2.add(jFirstName);
          pane2.add(jSurname);
          pane2.add(jCity);
          pane2.add(jCountry);
          pane2.add(jSSN);
          pane3.add(jbtnA);
          pane3.add(jbtnPrv);
          pane3.add(jbtnNt);
          pane3.add(jbtnDl);
          pane3.add(jbtnSrch);
          cont.add(pane1, BorderLayout.CENTER);
          cont.add(pane2, BorderLayout.LINE_END);
          cont.add(pane3, BorderLayout.SOUTH);
          jFirstName.addActionListener(this);
          jSurname.addActionListener(this);
          jCity.addActionListener(this);
          jCountry.addActionListener(this);
          jSSN.addActionListener(this);
          jbtnA.addActionListener(this);
          jbtnPrv.addActionListener(this);
          jbtnNt.addActionListener(this);
          jbtnDl.addActionListener(this);
          jbtnSrch.addActionListener(this);
          validate();
          setVisible(true);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          pack();
          setResizable(false);
          try
               Class.forname(sun.jdbc.odbc.JdbcOdbcDriver);
               String plato = jdbc:odbc:socrates;
               Connection con = DriverManager.getConnection(plato);
               stmt = con.createStatment();
          catch(SQLException ce)
               System.out.println(ce);
          catch(ClassNotFoundException ce)
               System.out.println(ce);
     public void actionPerformed(ActionEvent ae)
               try
                    if(ae.getSource().equals(jbtnA))
                                     fst = jFirstName.getText();
                         srn = jSurname.getText();
                         cty = jCity.getText();
                         cnty = jCountry.getText();
                         int sn = Interger.parseInt(jSSN.getText());
                                     ad = "Insert into Employees
values('"+fst+"',"+srn+"','"+cty+"','"+cnty+"','"+sn+"')";
                         stmt.executeUpdate(ad);
                         JOptionPane.showMessageDialog(this, "Your details have been
registered");
               catch(SQLException ce)
                    System.out.println(ce);
public static void main(String args[])
          Mainpage ObjFr = new Mainpage("Please fill this registration form");
}

Similar Messages

  • What is the password? registering database with the directory service

    I'm currently installing Oracle Collaboration Suite and everything being going fine until the postinstallation tasks for Oracle email.
    When I attempt to register the database with the directory service I'm not sure what I should be entering here.
    The guide says:
    cn=orcladmin should be entered in the User DN field but what is the password?
    and should orcl be replaced with my sid I entered during installation?
    I have tried a number of things but all I get is:
    Invalid Directory Service Credentials
    Thanks in advance for any help
    Best Regards
    Charlie

    No worries - found note in documentation regarding default password
    Thanks
    Charlie

  • I don't see the table I had create with the command line

    hi ,
    I just install sql developer, and connect to mydatabase, but I see a lot of tables who are not mine, but I don't see the one I have created. so could you tell me haow t make my tables to appear. or if I have to recreate them with wich command in sql developer? thanks

    Stranger.
    You do not need to recreate tables in the SQL Developer.
    The tables that you created and that they are in the database must be visualized, in accordance with the permissions.
    You are connected to the SQL Developer with the same user that created the table (owner)?
    The table that you desire to see appears below in the result of the command?
    select * from user_tables;

  • Is it possible to edit the table that contains sites with the passwords?

    for certain sites Firefox does not ask to remember the password, therefore this site will not appear in the security-table. By editing the table this problem could be bypassed.

    *Saved Password Editor: https://addons.mozilla.org/firefox/addon/saved-password-editor/

  • How to export some data from the tables of an owner with integrity?

    Hi to all,
    How to export some data from the tables of an owner with integrity?
    I want to bring some data from all tables in a single owner of the production database for development environment.
    My initial requirements are: seeking information on company code (emp), contract status (status) and / or effective date of contract settlement (dt_liq_efetiva) - a small amount of data to developers.
    These three fields are present in the main system table (the table of contracts). Then I thought about ...
    - create a temporary table from the query results table to contract;
    - and then use this temporary table as a reference to fetch the data in other tables of the owner while maintaining integrity. But how? I have not found the answer, because: what to do when not there is the possibility of a join between the contract and any other table?
    I am considering the possibility of consulting the names of tables, foreign keys and columns above, and create dynamic SQL. Conceptually, something like:
    select r.constraint_name "FK name",
    r.table_name "FK table",
    r.column_name "FK column",
    up.constraint_name "Referencing name",
    up.table_name "Referencing table",
    up.column_name "Referencing column"
    from all_cons_columns up
    join all_cons_columns r
    using (owner, position), (select r.owner,
    r.constraint_name fk,
    r.table_name table_fk,
    r.r_constraint_name r,
    up.table_name table_r
    from all_constraints up, all_constraints r
    where r.r_owner = up.owner
    and r.r_constraint_name = up.constraint_name
    and up.constraint_type in ('P', 'U')
    and r.constraint_type = 'R'
    and r.owner = 'OWNERNAME') aux
    where r.constraint_name = aux.fk
    and r.table_name = aux.table_fk
    and up.constraint_name = aux.r
    and up.table_name = aux.table_r;
    -- + Dynamic SQL
    If anyone has any suggestions and / or reuse code to me thank you very much!
    After resolving this standoff intend to mount the inserts in utl_file by a table and create another program to read and play in the development environment.
    Thinking...
    Let's Share!
    My thanks in advance,
    Philips

    Thanks, Peter.
    Well, I am working with release 9.2.0.8.0. But the planning is migrate to 10g this year. So my questions are:
    With Data Pump can export data just from tables owned for me (SCHEMAS = MYOWNER) parameterizing the volume of data (SAMPLE) and filters to table (QUERY), right? But parameterizing a contract table QUERY = "WHERE status NOT IN (2,6) ORDER BY contract ":
    1º- the Data Pump automatically searches for related data in other tables in the owner? ex. parcel table has X records related (fk) with Y contracts not in (2,6): X * SAMPLE records will be randomly exported?
    2º- for the tables without relation (fk) and which are within the owner (MYOWNER) the data is exported only based on the parameter SAMPLE?
    Once again, thank you,
    Philips
    Reading Oracle Docs...

  • How to truncate all the tables of my database

    hi guys
    I am using SQL Server 2012 , i need to delete all  the data present in my database .I mean i want to truncate all the tables in my database , so please suggest me the easiest way .

    If the tables are referenced by FK it will be failed.... 
    Basically you can use the below statetemnt
    DECLARE @TruncateStatement nvarchar(4000)
    DECLARE TruncateStatements CURSOR LOCAL FAST_FORWARD
    FOR
    SELECT
        N'TRUNCATE TABLE ' +
        QUOTENAME(TABLE_SCHEMA) +
        N'.' +
        QUOTENAME(TABLE_NAME)
    FROM
        INFORMATION_SCHEMA.TABLES
    WHERE
        TABLE_TYPE = 'BASE TABLE' AND
        OBJECTPROPERTY(OBJECT_ID(QUOTENAME(TABLE_SCHEMA) +
            N'.' +
            QUOTENAME(TABLE_NAME)), 'IsMSShipped') = 0
    OPEN TruncateStatements
    WHILE 1 = 1
    BEGIN
        FETCH NEXT FROM TruncateStatements INTO @TruncateStatement
        IF @@FETCH_STATUS <> 0 BREAK
        RAISERROR (@TruncateStatement, 0, 1) WITH NOWAIT
        EXEC(@TruncateStatement)
    END
    CLOSE TruncateStatements
    DEALLOCATE TruncateStatements
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to Move or Copy the Tables from One Database to Another Database ?

    HI,
          Can any one help me on this, How i can move or copy the tables from one database to another database in SQL server 2005 by using SQL query. Hope can anyone provide me the useful and valuable response.
    Thanks
    Gopi

    Hello,
    Maybe these links help you out
    http://www.microsoft.com/downloads/en/details.aspx?familyid=56E5B1C5-BF17-42E0-A410-371A838E570A&displaylang=en
    http://www.suite101.com/content/how-to-copy-a-sql-database-a193532
    Also, you can just detach the database make a copy and move it to the new server.

  • Goto: How to export some data from the tables of an owner with integrity?

    Hi to all,
    Help please: How to export some data from the tables of an owner with integrity?
    My thanks in advance,
    Philips

    Thanks, Peter.
    Well, I am working with release 9.2.0.8.0. But the planning is migrate to 10g this year. So my questions are:
    With Data Pump can export data just from tables owned for me (SCHEMAS = MYOWNER) parameterizing the volume of data (SAMPLE) and filters to table (QUERY), right? But parameterizing a contract table QUERY = "WHERE status NOT IN (2,6) ORDER BY contract ":
    1º- the Data Pump automatically searches for related data in other tables in the owner? ex. parcel table has X records related (fk) with Y contracts not in (2,6): X * SAMPLE records will be randomly exported?
    2º- for the tables without relation (fk) and which are within the owner (MYOWNER) the data is exported only based on the parameter SAMPLE?
    Once again, thank you,
    Philips
    Reading Oracle Docs...

  • Comparing data in the database with the input text

    hi there i have problem with the comparing data in the database with the input text. here is the piece of code of mine:
    //declaration
    datasourcedb.connect();
    String stcode = req.getParameter("txtCode");
    ResultSet rs = null;
    String action = req.getParameter("action");
    ResultSet portquery = null;
    if (action.equals("SELL"))
    -->portquery = datasourcedb.query("SELECT stockcode FROM portfolio where stockcode =\'"+ stcode + "\'");
    -->portquery.next();
    -->if((portquery.wasNull()) == true)
    disp = req.getRequestDispatcher("error.jsp"); }
    else */
    Status = "Sell";
    datasourcedb.close();
    with the code that i marked with --> it doesnt work since i have to compare the input text stcode with stockcode in the db. could anyone tell me how to compare it?
    regards
    virginia

    i have try to change into this code:
    if (action.equals("SELL"))
    portquery = datasourcedb.query("SELECT distinct stockcode FROM portfolio where stockcode =\'"+ stcode + "\' + and userName = \'"+ user + "\'");
    if(portquery.next()) {
    Status = "Sell";}
    else {               
    disp = req.getRequestDispatcher("error.jsp");
    but so far the coding doesnt give any result.... could anyone help me? since the coding does not reach status n the disp

  • I need to copy data from a table in one database (db1) to another table in

    Hi
    I need to copy data from a table in one database (db1) to another table in another database (db2).
    I am not sure if the table exists in db2,,,if it doesnot it needs to be created as well data also needs to be inserted...
    How am I supposed to this using sql statements..?
    I shall be happy if it is explained SQL also...
    Thanking in advance

    How many rows does the table contains? There are manyway you can achieve this.
    1. export and import.
    2. create a dblink between two databases and use create table as select, if structure doesnot exists in other database, if structure exists, use, insert into table select command.
    example:
    create a dblink in db2 database for db1 database.
    create table table1 as select * from table1@db1 -- when there is no structure present
    -- you need to add constraints manually, if any exists.
    insert into table1 select * from table1@db1 -- when there is structure present.
    If the table contains large volume of data, I would suggest you to use export and import.
    Jaffar

  • Insert data into fact table from source database tables

    here i try to insert data into fact table from source database tables here is the query 
    ALTER procedure [dbo].[facttable]
    as
    insert into [pp dw].dbo.Dimfact(Prod_ID,Production_ID,Material_ID,Equip_ID,WC_ID,Recipe_ID,Quantity,costprice)
    select Products.[Product ID],[Production ID],Materials.[Material ID],[Equipment ID],[Work Centre ID],[Recipy ID],Quantity,[cost price]
    from
    [PRODUCTION PLANNING 2].dbo.[Products],
    [PRODUCTION PLANNING 2].dbo.[Production Detail],
    [PRODUCTION PLANNING 2].dbo.[Material category],
    [PRODUCTION PLANNING 2].dbo.[Materials],
    [PRODUCTION PLANNING 2].dbo.[Equipment],
    [PRODUCTION PLANNING 2].dbo.[Working Centre] ,
    [PRODUCTION PLANNING 2].dbo.[Recipies]
    where
    Products.[Product ID] in (13, 14, 15, 16, 17) and
    [Production Detail].[Production ID] in (1, 2, 3) and
    [Materials].[Material ID] in (1, 2, 3, 4, 5) and
    [Equipment].[Equipment ID] in (1, 2, 3, 4) and
    [Working Centre].[Work Centre ID] in (1, 2, 3) and
    [Recipies].[Recipy ID] in (1, 2, 3) and
    [Material category].[Category ID] in (8, 9, 10, 11, 12, 13)
    and when i execute query it shows me error 
    The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Dimfact_Dimproduct". The conflict occurred in database "pp dw", table "dbo.Dimproduct", column 'Prod_ID'.
    ERD IS
    HOW TO SOLVE THIS PROBLEM?

    I cant see any join conditions in your query posted. Whats the purpose of the query above. It will just bring you a cartesian product (cross join) of tables involved subjected to filters. Are you sure this is the correct query?
    The error you're getting may be because you've not yet populated DimProduct or may be because of logic you used in popultaing DimProduct causing it to miss some records which is what query is referring to in above case.
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Creating a Standby Database with the Same Directory Structure

    Hello gurus,
    I am self-learning the feature Oracle Data Guard, so I am testing it on Oracle 10g R2.
    At Oracle documentation there is a section F.4.: Creating a Standby Database with the Same Directory Structure*, that explains how to create a standby database with RMAN but there is something that I don´t understand:
    In the standby server, I created a database with the SID equal to production database* with the objetive to have the same directory structure, but when I try to startup nomount the standby database with pfile appear this expected error:
    ORA-16187: LOG_ARCHIVE_CONFIG contains duplicate, conflicting or invalid attributes
    So my question is: Is possible have the Same Directory Structure on both: Production and StandBy server?
    Thanks in advanced.

    Uwe and mseberg: thanks for your quick answers
    I have a doubt: How can you have the same directory structure if you have differents SIDs?, for example if you follow the OFA suggestions you would must have:
    On Production server: */u01/app/oracle/oradata/PRIMARY/system.dbf*
    On StandBy server: */u01/app/oracle/oradata/STANDBY/system.dbf*
    Or you created the directory structure manually on StandBy server? For example replacing the string STANDBY* to PRIMARY* before create the database using dbca.
    Do you understand my doubt? Excuse me for my english.
    Thanks.

  • What are the tables for Partner Fuction regarding the Vendors Purchasing ?

    Hello Gurus,
    What are the tables for Partner Fuction regarding the Vendors Purchasing Organisation. I need the Partner Function Key, Parner Function Name, Number and the Name of the Number.
    Thanx in advance,
    Ramona

    Hi Jürgen,
    I know that table but it is only showing me the technical name of the Partner Function and I need also the rest: the text(name), number and the number name (text). I presume there are other tables for those infos.
    I am not sure if I understand what are these. I just want the table to upload the data to BW.

  • What are the tables impacted when we done the migo

    hi,
    what are the tables impacted when we done the migo.

    The tables invoved are :-
    MARD -   Storage Location Data for Material
    MARC - Plant Data for Material
    MSEG - Document Segment: Material
    MBEW - Material Valuation
    MKPF - Headr : Material Document
    EKBE - History per Purchasing Document
    EBEW - Sales Order Stock Valuation
    Edited by: Briesh Patel on Apr 22, 2008 4:42 PM

  • How to handle the table control While working with LSMW?

    How to handle the table control While working with LSMW?

    its possible in lsmw,
    Hi,
    LSMW will have a Indicator for headr and itam, i do not remember the correct field, but it will have an indicator, check the fields, there will be a single charecter lenght field, that should be the indicator, and using that we can write the logic.
    check that single charecter field, it that is X that means the header record is processed, and do the items.
    and, this is another way, try this out also
    YOu can do this in "Define Source Structures" step,
    the HEADER is defined first,
    then the DETAIL below the HEADER.
    add the fields to the structures.
    Both should have some common key field
    Please take care that the name of the common field is the same.
    Once you do this it is linked. The you have a header and item corresponding to that header. then run the LSMW as you would.
    Thanks

  • Is it possible to create a Clone database with the same name of source db ?

    Is it possible to create a Clone database with the same name of source db using RMAN ...
    DB version is 11.2.0.2
    Is it possible to clone a 11.2.0.2 database to 11.2.0.3 home location directly on a new server . If it starts in a upgrade mode , it is ok ....

    user11919409 wrote:
    Is it possible to create a Clone database with the same name of source db using RMAN ...
    yes
    >
    DB version is 11.2.0.2
    Is it possible to clone a 11.2.0.2 database to 11.2.0.3 home location directly on a new server . If it starts in a upgrade mode , it is ok ....yes
    Handle:     user11919409
    Status Level:     Newbie (10)
    Registered:     Dec 7, 2009
    Total Posts:     102
    Total Questions:     28 (22 unresolved)
    why do you waste time here when you rarely get any answers to your questions?

Maybe you are looking for

  • Creating a job in schema when can't login in that schema

    there is a requirement that I've to create a job in a schema, but i don't have that schema's password,but I've that server's SYSDBA's password,means I can login into SYS account as SYSDBA, but I've to create a job in that schema. how is it possible,

  • Is this a new Apple? Macbook Pro issues - Data recovery.

    I am a long time supporter of Apple (20 some odd years) but things seem different now and I am not talking about the "think different" from the old ad campaigns. Apple is a part of every aspect of my life with my personal machines and gadgets to the

  • Capturing OIM User Attribute Properties in OIM Export

    I spent a significant amount of time going through the UI and creating UDFs and tweaking my existing and UDF fields to make sure specific ones are hidden and others are shown. I then used the deployment manager to export the User Metadata. Upon impor

  • Restricting business areas as per company code

    Dear friends, The Company Code is 1000. This company code has four Business areas IQE,DQE,DPS,KQC. The Requirement is that when the user selects the company code 1000, He must restricted to pick only the business areas IQE,DQE,DPS,KQC. Please advise

  • Bookmarks in fullscreen

    When I go to fullscreen mode in Youtube, Mozilla hides my bookmarks pane, which is what I want. When I exit fullscreen however, the pane doesn't come back, I have to set it to show manually every time. Is there a way to change this so that it hides f