0% found this document useful (0 votes)
25 views

Note Taking

This document contains code for two Java programs: 1) A Person class with private name and age fields and getter/setter methods to work with a Person object. The main method gets user input and demonstrates using the Person object. 2) A GUI program with buttons to insert and delete a name from a database table. It connects to a MySQL database and executes INSERT and DELETE SQL statements on button clicks.

Uploaded by

Manu yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Note Taking

This document contains code for two Java programs: 1) A Person class with private name and age fields and getter/setter methods to work with a Person object. The main method gets user input and demonstrates using the Person object. 2) A GUI program with buttons to insert and delete a name from a database table. It connects to a MySQL database and executes INSERT and DELETE SQL statements on button clicks.

Uploaded by

Manu yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

JAVA BEANS PROGRAM

import java.util.Scanner;

class Person {

private String name;

private int age;

public void setName(String name) {

this.name = name;

public void setAge(int age) {

this.age = age;

public String getName() {

return name;

public int getAge() {

return age;

public class NewJAva {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

Person p = new Person();

System.out.print("Enter your name: ");

String name = sc.nextLine();

p.setName(name);

System.out.print("Enter your age: ");

int age = sc.nextInt();

p.setAge(age);

System.out.println("Name: " + p.getName());

System.out.println("Age: " + p.getAge());

1
JAVA JDBC PROGRAM
package greeb;

/**

* @author Admin

*/

import java.awt.*;

import java.awt.event.*;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

public class DataInsertion extends Frame implements ActionListener {

Button b1, b2;

TextField t1,t2;

Label l1,l2;

DataInsertion()

setVisible(true);

setSize(400,400);

b1=new Button("Insert");

b2=new Button("Delet");

t1=new TextField(20);

l1=new Label("Enter the name");

setLayout(new FlowLayout());

add(l1);add(t1);add(b1);add(b2);

b1.addActionListener(this);

b2.addActionListener(this);

public void actionPerformed(ActionEvent ae)

System.out.println("Debug-1");

if(ae.getSource()==b1)

String name=t1.getText();

try{

Class.forName("com.mysql.cj.jdbc.Driver");

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/
coll","root","mysql"); //here sonoo is database name, root is username and
password

Statement stmt=con.createStatement();

// String sql = "insert into insertion values ('" +name+ "');";

stmt.executeUpdate("insert into insertion values ('" +name+ "');");


con.close();

catch(ClassNotFoundException | SQLException e)


System.out.println(e);


if(ae.getSource()==b2)


dispose();

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy