What are the codes when you cancel a list of names in the database in a certain field?

This is the situation:

I made a reservation in a certain hotel. Of course they asked my name, what kind of room. . Automatically, it saved on the database of their system. But suddenly, i changed my mind. . I made a cancellation on my reservation I made. .

In java program what are the codes necessary to cancel if the database is connected that needs automatic cancellation in the system???

Please help. . I'm just a beginner. . Thanks!

I'm not so sure of my codes:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class database
{

    public static void main(String [] args)
    {


            int d=0;
            int ans=1;
            String msg;

           do
         {

            int select = 0;

            String select0 = JOptionPane.showInputDialog("Enter Customer Name ");

            //select = Integer.parseInt(select0);

            if(select == 1)
         {
                       if(d==0)
                            {
                                 Delete sweetie = new Delete();
                                 d++;

                            }
                            }

            }





    while(ans==1);



}}



/////////////////////////////////////////////////






import java.sql.*;
import javax.swing.*;

public class Cancel
{
    public Cancel()

    {
           String msg1=JOptionPane.showInputDialog("Enter name: " );

         try
      {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          Connection conn = DriverManager.getConnection("jdbc:odbc:trial","test","database");
          Statement stmt = conn.createStatement();


          String query;


        try
          {


            JOptionPane.showMessageDialog(null, "Cancel Customer Reservation");
            PreparedStatement jane = conn.prepareStatement("CANCEL * FROM RESERVATION  WHERE  name = (?) ");
            jane.setString(1,msg1);              
            jane.executeUpdate();  


              JOptionPane.showMessageDialog(null,"Cancellation successful!");

              jane.close();
              stmt.close();
              conn.close();
           }


           catch (Exception e)
           {
               e.printStackTrace();
           }  
        }


           catch (ClassNotFoundException cnfex)
           {
               System.err.println("Failed to load JDBC/ODBC driver");
               cnfex.printStackTrace();
               System.exit(1);

            }


            catch(SQLException sqlex)
            {
                System.err.println(sqlex);
                sqlex.printStackTrace();
            }
        }
    }

> Please help. . I'm just a beginner. . Thanks!

Start by reading the stickies at the top of the forum to get started with Java.

The forum rules forbid / discourage ready solutions to the problem posted by members and help is rendered only if an effort is shown from your side.

Actually this is an SQL Question rather than a Java question, If you want to delete a row from a table, you use the "DELETE" statement.
The following is an illustration,
Consider we have a table "User" with columns "UserName" and "Age", Now if I want to delete all records from the table where UserName is "XYZ", the corresponsing query would be:-

DELETE
FROM User
WHERE UserName="XYZ"

Also next time you post Java code,be sure to wrap the [code=java] and [/code] tags around it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.