database

database

In my project,i want the user to specify the name of the database he wants to create in mysql and then also the name of the table along with the column names he wants in that database....Im doing my project in netbeans...swings.......If it is possible kindly help me Thank You...

View Answers

February 16, 2011 at 11:04 AM

Java Create database and table using Java Swing

import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
class  CreateDatabase
{
    public static void main(String[] args) 
    {
        JFrame f=new JFrame();
        JLabel lab=new JLabel("Enter Database name: ");
        JLabel lab1=new JLabel("Enter Table name: ");
        final JTextField text=new JTextField(20);
        final JTextField text1=new JTextField(20);
        JButton b=new JButton("Create");
        f.setLayout(null);
        lab.setBounds(10,10,150,20);
        text.setBounds(180,10,150,20);

        lab1.setBounds(10,40,150,20);
        text1.setBounds(180,40,150,20);
        b.setBounds(180,70,100,20);
        b.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            String st=text.getText();
             String st1=text1.getText();
            try{
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/", "root", "root");
            Statement stmt=con.createStatement();
            String sql = "CREATE DATABASE "+st;
            stmt.executeUpdate(sql);
            stmt.close();
            con.close();
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+st, "root", "root");
            Statement sta = conn.createStatement();
            String table = "CREATE TABLE "+st1+"(id integer, name varchar(10))";
            sta.executeUpdate(table);
            JOptionPane.showMessageDialog(null, "Database and table are created successfully");
            }
            catch(Exception ex){
            System.out.println(ex);
            }
            }
        });
        f.add(lab);
        f.add(text);
        f.add(lab1);
        f.add(text1);
        f.add(b);
        f.setVisible(true);
        f.setSize(350,180);
    }
}









Related Tutorials/Questions & Answers:
database
database  database
database
database  database application
Advertisements
database
database  the code for initializing the database connection
database
database  i want to let the user select the name of database and then delete that database.......im doing project in swings netbeans
database
database  use of hyperlink to show the data from database
database
database  i need to insert time in my database. i need a code to insert time in my database. its very urgent
database
database  im doing my project in netbeans swings...wn a user wants to create a database from the gui...i want to display an error msg if a database with that name already exists and if it does not exist new database should
database
database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover... links: Connect JSP with database Mysql Connect Java with database Mysql
database
database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover... links: Connect JSP with database Mysql Connect Java with database Mysql
database
database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover... links: Connect JSP with database Mysql Connect Java with database Mysql
database
database  I wanted to know if it is possible to create a database in mysql by letting the user enter the name of the database in swing gui..im doing my project in netbeans...Thank You
database
database  I wanted to know if it is possible to establish database connection on a remote pc with mysql using java swings from netbeans and then create a database on the remote pc.... Kindly help me
DATABASE
DATABASE  How can i get combo box values from database?? or how can i get values in the drop down menu of the html which is similar to dat of combo box in java - from database
Database
Database  How to represent data from database in a tree?   Please visit the following link: Retrieve data from database in tree using Java Swing
Database
Database  I am working in jsf2.Fro a demo i created database in ms access.no wi want to retrive a record from database for a particular data.I need help as I am stuck
Database
Database  from java code i have to retrieve some data from a database, which is present in a different timezone. Scenario :- My database... in database timezone is 9PM 15APR2012. I want to retrieve something from database
DATABASE
DATABASE  I can't send different information from different form into a single table in my database
Database
Database  Can i get a code for database connectivity Myeclipse 3.3 to MySql manager 2005
database
database  dateofbirth is not save into the database while i am enter from html browser.it shows as null.whats the reason
database
database  sir.. how we can uplaod the database in the data file(ms access)please send me a solution
database
database  how we ca upload the data in the database file(ms access
database
database  hi i want to develop one patient database can any one provide me the guide
database
database  In my project where u helped me to display the databases present im mysql database on the Jlist and then the respective tables in that database on another jlist and then the column names on another jlist I dont want
database
database  In my project,i want the user to specify the name of the database he wants to create in mysql and then also the name of the table along with the column names he wants in that database....Im doing my project in netbeans
database
database  Im doing my project in java swings...netbeans I wanted java source code to establish connection to postgresql_8.1 using jdbc and create a user defined database and a table in that database and insert values Plz help me
database
database  Can you please help me to establish database connection to ms sql 2000 from java swing in netbeans
database
database  i need optimised searching algorithm to retrieve the data from the database and optimised ranking algorithm to display the reults into the user
database
the names of the databases present in mysql database on a Jlist that is already present on the gui and when the user selects a particular database,the tables present under that database should be displayed on another Jlist which is present
database
database  I want to let the user select one of the database type... give the name of the database name that he want to create in a textfield... database..im doing my project in java swings.....netbeans Kindly help me ThankYou
database
database  I wanted to know if it is possible to take the fields of a table from a user and then create a table in mysql database......im doing my project in swings netbeans Plz help me ThankYou
Database
Database  In MYSQL database i m given as the email id as the char but i enter the email id it gives manually error.how can i recover that error   For email, use the data type varchar
Database
Database  is it possible to view the query code after executing it.if yes tell me the procedure.   Yes, if you want to retrieve the data that is stored in database, then use the given query: select * from student
Database
Database   select * from student i am not asking this.i am asking about that the command line code like create table student(..........) like this way
database
database  how to get information about database like, what are the names of tables that database includes ? what are the names of fields in corresponding tables ? in mysql database on linux environment   Here is a code
database
database  Is it possible to let the user first type the database and table name in textfields and then provide him a taxt area to type an insert query to insert data in that table and then execute the query.....The project
Database
Database  hi i don't know any thing about database please help me and explain it for me . thank you   you can get more data base programs from here View Programs here
database
database  how to search data from database using jsp & how to rank the searched result using any searching algorithm   Please visit the following links: http://www.roseindia.net/jsp/user-search.shtml http
Database
Database  Hi, i need help building a database based on something like...), multiplicity (or cardinality), in the context of the database system (i.e. give... the database, create and populate tables, query individual tables. (You must
database
; Have you run this query directly into the Mysql database? Here it works properly.   Have you run this query directly into the Mysql database? Here
Database
then automatically save that subjects in my database for this i want procedure some
database
user required data from the database and rank the results and display... that) based on that system search it to the database and rank the results and retrieve
database
database  How can i get combo box values from database?? or how... of combo box in java - from database? you had given me the answer <%@page... name officename and database name jsw   <%@page import="java.sql.
Database
Database  in my database i insert the first name and last name as('abc','def')but it gives error.plz send me the query how can we insert the first name,last name,email id,bate of birth,and mobile number.   Here
Database
Database  in my database i insert the first name and last name as('abc','def')but it gives error.plz send me the query how can we insert the first name,last name,email id,bate of birth,and mobile number.   Here
database
database  i am created one table in mysql database with one of the column name is emailid.now i want to write a java code that if the mail id... or not. If it is already exist in database, then show a message 'Already exists
DATABASE
DATABASE  how to store data into database using JDBC & SQL   import java.sql.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; class InsertData{ public static void main(String[] args
database
database  in my database i add some fields.the total fields are first name,last name,email,password,conform password,date of birth,age,gender,address,country,state,city,telephone,mobile, how did u hear about us. but i got some
database connection
database connection  how to connect the jsp page with database
database connection
database connection  i wanted to no how to connect sqlite database through netbeans? is it posible to connect it to a database that is on a remote pc? thank you
Connect to the database
Connect to the database  how to connect to the database in the iphone

Ads