Menu
Question Index
...


Write a program to get the create table query for MySQL by taking the entity object. Note that you need to use reflection api to do this. If the input entity has a field with name 'id', assume that is a primary key. The other fields should be sorted by name.

Input (Object) Output (String)
new Student() CREATE TABLE STUDENT(ID INTEGER PRIMARY KEY, GENDER BOOL, MARKS INTEGER, NAME VARCHAR, PERCENTAGE DOUBLE (3, 2), SECTION VARCHAR(1));
new Employee() CREATE TABLE EMPLOYEE(ID INTEGER PRIMARY KEY, DESIGNATION VARCHAR, GENDER BOOL, NAME VARCHAR, SALARY DOUBLE (3, 2), WORKINGHOURS SMALLINT);
new Mobile() CREATE TABLE MOBILE(COMPANYNAME VARCHAR, MEMORY DOUBLE (3, 2), MODELNAME VARCHAR, PIXEL FLOAT, PRICE DOUBLE (3, 2), RESOLUTION INTEGER);
new College() CREATE TABLE COLLEGE(ADDRESS VARCHAR, COLLEGECODE VARCHAR, COLLEGENAME VARCHAR, CONTACT BIGINT, NUMBEROFBRANCHES INTEGER, NUMBEROFFACULTY INTEGER, NUMBEROFSTUDENTS INTEGER);

class CreateTableForMysql

{    public static void main(String s[])
    {
        Student student = new Student();
        String query = createTableQuery(student);
        System.out.println(query);

    }


public static String createTableQuery(Object entity) {
//Write code here to get create table query using the entity object
}

//If required write any additional methods here
}
class Student {

String name;
boolean gender;
int marks;
double percentage;
char section;
int id;
}

class Employee {

double salary;
String name;
String designation;
int id;
boolean gender;
short workingHours;
}

class Mobile {

String companyName;
String modelName;
double price;
double memory;
float pixel;
int resolution;
}

class College {

int numberOfStudents;
int numberOfBranches;
int numberOfFaculty;
String collegeCode;
String address;
String collegeName;
long contact;
}

Doubts

Problems

Topic: Other Advanced Topics In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App