Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.util.Scanner;
- public class Create {
- public static void main(String[] args) {
- try {
- Scanner s=new Scanner(System.in);
- Class.forName("com.mysql.jdbc.Driver");
- Connection con=DriverManager.getConnection("jdbc:mysql://localhost/fila","root","filimon");
- PreparedStatement ps=con.prepareStatement("create table ?(? int(4)primary key,? varchar(20),? float(4,2))");
- System.out.print("enter the table name to create: ");
- String name=s.nextLine();
- ps.setString(1, name);
- System.out.print("enter the primarykey column name: ");
- String priname=s.nextLine();
- ps.setString(2, priname);
- System.out.print("enter the second column name: ");
- String secname=s.nextLine();
- ps.setString(3, secname);
- System.out.print("enter the third column name: ");
- String thrname=s.nextLine();
- ps.setString(4, thrname);
- int i=ps.executeUpdate();
- System.out.println(i+" table created");
- ps.close();
- con.close();
- s.close();
- } catch (Exception e) {
- System.err.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement