Friday, March 21, 2025

SQL query to create a table to store student information:

 Here is a SQL query to create a table to store student information:


```

CREATE TABLE Students (

    StudentID INT PRIMARY KEY,

    FirstName VARCHAR(50) NOT NULL,

    LastName VARCHAR(50) NOT NULL,

    DateOfBirth DATE,

    Email VARCHAR(100) UNIQUE,

    Phone VARCHAR(20),

    Address VARCHAR(200),

    City VARCHAR(50),

    State VARCHAR(50),

    Country VARCHAR(50),

    PostalCode VARCHAR(10),

    Course VARCHAR(50),

    Department VARCHAR(50)

);

```


Here's a brief explanation of each column:


- `StudentID`: Unique identifier for each student.

- `FirstName` and `LastName`: Student's name.

- `DateOfBirth`: Student's date of birth.

- `Email`: Student's email address (unique).

- `Phone`: Student's phone number.

- `Address`, `City`, `State`, `Country`, and `PostalCode`: Student's address.

- `Course` and `Department`: Student's course and department.


To insert data into the table:


```

INSERT INTO Students (

    StudentID,

    FirstName,

    LastName,

    DateOfBirth,

    Email,

    Phone,

    Address,

    City,

    State,

    Country,

    PostalCode,

    Course,

    Department

)

VALUES (

    1,

    'John',

    'Doe',

    '1990-01-01',

    'john.doe@example.com',

    '123-456-7890',

    '123 Main St',

    'Anytown',

    'CA',

    'USA',

    '12345',

    'Computer Science',

    'Engineering'

);

```


To retrieve data from the table:


```

SELECT * FROM Students;

```


To update data in the table:


```

UPDATE Students

SET FirstName = 'Jane'

WHERE StudentID = 1;

```


To

 delete data from the table:


```

DELETE FROM Students

WHERE StudentID = 1;

```

Simple Java program using Swing for GUI and Google Translate API for translation:

 Here is a simple Java program using Swing for GUI and Google Translate API for translation:


import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.net.URL;

import org.json.JSONObject;


public class Translator extends JFrame {

    private JTextArea textArea;

    private JComboBox<String> languageComboBox;

    private JButton translateButton;


    public Translator() {

        setLayout(new BorderLayout());


        // Text Area

        textArea = new JTextArea(20, 40);

        add(new JScrollPane(textArea), BorderLayout.CENTER);


        // Language Combo Box

        String[] languages = {"English", "Spanish", "French", "German", "Italian", "Portuguese", "Chinese", "Japanese", "Korean"};

        languageComboBox = new JComboBox<>(languages);

        add(languageComboBox, BorderLayout.NORTH);


        // Translate Button

        translateButton = new JButton("Translate");

        translateButton.addActionListener(new ActionListener() {

            @Override

            public void actionPerformed(ActionEvent e) {

                translateText();

            }

        });

        add(translateButton, BorderLayout.SOUTH);


        setSize(600, 400);

        setDefaultCloseOperation(EXIT_ON_CLOSE);

        setVisible(true);

    }


    private void translateText() {

        String text = textArea.getText();

        String language = (String) languageComboBox.getSelectedItem();

        String translatedText = translate(text, language);

        textArea.setText(translatedText);

    }


    private String translate(String text, String language) {

        try {

            URL url = new URL("https://translation.googleapis.com/language/translate/v2?key=YOUR_API_KEY");

            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            connection.setRequestMethod("POST");

            connection.setRequestProperty("Content-Type", "application/json");


            JSONObject json = new JSONObject();

            json.put("q", text);

            json.put("target", getLanguageCode(language));


            connection.setDoOutput(true);

            connection.getOutputStream().write(json.toString().getBytes());


            int responseCode = connection.getResponseCode();

            if (responseCode == 200) {

                BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

                String line;

                StringBuilder response = new StringBuilder();

                while ((line = reader.readLine()) != null) {

                    response.append(line);

                }

                reader.close();


                JSONObject jsonResponse = new JSONObject(response.toString());

                return jsonResponse.getJSONArray("data").getJSONObject(0).getString("translations").getJSONObject(0).getString("translatedText");

            } else {

                return "Error: " + responseCode;

            }

        } catch (Exception e) {

            return "Error: " + e.getMessage();

        }

    }


    private String getLanguageCode(String language) {

        switch (language) {

            case "English":

                return "en";

            case "Spanish":

                return "es";

            case "French":

                return "fr";

            case "German":

                return "de";

            case "Italian":

                return "it";

            case "Portuguese":

                return "pt";

            case "Chinese":

                return "zh-CN";

            case "Japanese":

                return "ja";

            case "Korean":

                return "ko";

            default:

                return "en";

        }

    }


    public static void main(String[] args) {

        SwingUtilities.invokeLater(new Runnable() {

            @Override

            public void run() {

                new Translator();

            }

        });

    }

}



Replace `YOUR_API_KEY` with your actual Google Translate API key.


Note:

- This program uses the Google Translate API, which requires a API key.

- The program translates the text in the text area to the selected language.

- The program uses the `getLanguageCode` method to get the language

 code for the selected language.

- The program uses the `translate` method to translate the text using the Google Translate API.

Featured posts

Ethiopian culture calendar language

Ethiopian culture, calendar, language  The Ethiopian language, specifically Amharic, uses a script called Ge'ez script. It consists of 3...

Popular posts