0

I have been created java register using java swing:

Here is registration.java code:

   package student;
import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

public class Registration extends JFrame implements ActionListener
{ 

  JLabel l1, l2, l3, l4, l5, l6, l7, l8;

  JTextField tf1, tf2, tf5, tf6, tf7;

  JButton btn1, btn2;

  JPasswordField p1, p2;



  Registration()
   {

      setVisible(true);

      setSize(700, 700);

      setLayout(null);

      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      setTitle("Registration Form in Java");



      l1 = new JLabel("Registration Form in Windows Form:");

      l1.setForeground(Color.blue);

      l1.setFont(new Font("Serif", Font.BOLD, 20));
      l2 = new JLabel("Name:");

      l3 = new JLabel("Email-ID:");

      l4 = new JLabel("Create Passowrd:");

      l5 = new JLabel("Confirm Password:");

      l6 = new JLabel("Country:");

      l7 = new JLabel("State:");

      l8 = new JLabel("Phone No:"); 

      tf1 = new JTextField();

      tf2 = new JTextField();

      p1 = new JPasswordField();

      p2 = new JPasswordField();

      tf5 = new JTextField();

      tf6 = new JTextField();

      tf7 = new JTextField();



      btn1 = new JButton("Submit");

      btn2 = new JButton("Clear");



      btn1.addActionListener(this);

      btn2.addActionListener(this);



      l1.setBounds(100, 30, 400, 30);

      l2.setBounds(80, 70, 200, 30);

      l3.setBounds(80, 110, 200, 30);

      l4.setBounds(80, 150, 200, 30);

      l5.setBounds(80, 190, 200, 30);

      l6.setBounds(80, 230, 200, 30);

      l7.setBounds(80, 270, 200, 30);

      l8.setBounds(80, 310, 200, 30);

      tf1.setBounds(300, 70, 200, 30);
      tf2.setBounds(300, 110, 200, 30);

      p1.setBounds(300, 150, 200, 30);

      p2.setBounds(300, 190, 200, 30);

      tf5.setBounds(300, 230, 200, 30);

      tf6.setBounds(300, 270, 200, 30);

      tf7.setBounds(300, 310, 200, 30);

      btn1.setBounds(50, 350, 100, 30);

      btn2.setBounds(170, 350, 100, 30);
      add(l1);

      add(l2);

      add(tf1);

      add(l3);

      add(tf2);

      add(l4);

      add(p1);

      add(l5);

      add(p2);

      add(l6);

      add(tf5);

      add(l7);

      add(tf6);

      add(l8);

      add(tf7);

      add(btn1);

      add(btn2);

  }
  public void actionPerformed(ActionEvent e)
  {

     if (e.getSource() == btn1)
      {

         int x = 0;

         String s1 = tf1.getText();

         String s2 = tf2.getText();



         char[] s3 = p1.getPassword();

         char[] s4 = p2.getPassword(); 

         String s8 = new String(s3);

         String s9 = new String(s4);



         String s5 = tf5.getText();

         String s6 = tf6.getText();

         String s7 = tf7.getText();

         if (s8.equals(s9))
        {

             try
            {

                 Class.forName("oracle.jdbc.driver.OracleDriver");

                 Connection con = DriverManager.getConnection("jdbc:oracle:thin:rajesh/local@localhost");
                 PreparedStatement ps = con.prepareStatement("insert into emp values(?,?,?,?,?,?)");

                 ps.setString(1, s1);

                 ps.setString(2, s2);

                 ps.setString(3, s8);

                 ps.setString(4, s5);

                 ps.setString(5, s6);

                 ps.setString(6, s7);

                 ResultSet rs = ps.executeQuery();

                 x++;

                 if (x > 0)
                 {

                     JOptionPane.showMessageDialog(btn1, "Data Saved Successfully");

                 }

             }
       catch (Exception ex)
             {

                 System.out.println(ex);

             }

         }
       else
        {

             JOptionPane.showMessageDialog(btn1, "Password Does Not Match");

         } 

     } else
     {

         tf1.setText("");

         tf2.setText("");

         p1.setText("");

         p2.setText("");

         tf5.setText("");

         tf6.setText("");

         tf7.setText("");

     }

 } 

 public static void main(String args[])
{

     new Registration();

 }
}

When i run this, it shows

"ORA-00942: table or view does not exist".

But i have created database user and table in oracle 11g.

These steps are i did in sql command line:

connect
username:
password:
"connected"
create user rani identifed by pcs;
grant connect, resource to rani;
"granted"

After that, for creating table, i have a file called reg.sql:

create table emp
 (
    name varchar2(30), email varchar2(40),
    pass varchar2(30), count varchar2(30),
    state varchar2(30), phone number(15)
 );

So i have to import this file for store student details.

May i know, how to do this,? Thanks in advance.

2 Answers 2

1
connect
username:
password:
"connected"
create user rani identifed by pcs;
grant connect, resource to rani;
"granted"
create table reg(pid integer primary key,name varchar2(50));
"table created"

You have created the table not in the RANI schema. You need to first connect to RANI user and then issue the CREATE TABLE statement. As of now, your table REG resides in the USER that you initially connected to.

Update Based on OP's request about executing the script.

You could execute it as a script. Just add everything in the script itself and call the script.

For example, your reg.sql would look like this:

BEGIN
   EXECUTE IMMEDIATE 'DROP TABLE emp';
EXCEPTION
   WHEN OTHERS THEN
      IF SQLCODE != -942 THEN
         RAISE;
      END IF;
END;
/
create table emp
 (
    name varchar2(30), email varchar2(40),
    pass varchar2(30), count varchar2(30),
    state varchar2(30), phone number(15)
 );

You just need to execute the script with the complete directory where it is placed locally. Let's say the reg.sql is placed in C:\REG

sqlplus -s rani/pcs@sid << EOF
@C:\REG\reg.sql;
EXIT;
EOF
Sign up to request clarification or add additional context in comments.

10 Comments

Your code still says insert into reg, Once again, does reg table exists? Which table do you want to really insert into?
Ok, this is one last time I am telling you repeatedly. Once you are connected to SQLPlus, you don't ahve to use the keyword SQLPlus again. Let's say you have created user rajesh with password as local. Do CONNECT. Enter RAJESH as username and enter local as password. Once you are connected to RAJESH user, then @c:\file
yes i got it.. thanks.. then how to view my data in database?.. thanks
i want to view like this s8.postimg.org/y4lchfxqd/Untitled_2_copy.png, i mean i want to view in oracle database engine.. thanks
|
0

Create your table into rani schema. For java it can as below:

Connection con = DriverManager.getConnection("jdbc:oracle:thin:rani/pcs@localhost");
Statement statement = connection.createStatement();
statement.executeUpdate("create table ...");

6 Comments

i can't understand, for creating table.. because i m new to java.. i have reg.sql file.. may i know ,is there way to import my project.?
@sona, exeute your script with statement.executeUpdate(myScriptFromRegSQL);
@ Michael Kazarian: i heard need sql developer to import sql file.. is it right?
@sona, yes, you can execute script from SQL Developer or from SQL Plus. My answer about create table from your own code.
ok. how to change with my existing code, i mean my posted code? thanks
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.