Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.PreparedStatement;
  4. import java.util.Scanner;
  5.  
  6. public class Create {
  7. public static void main(String[] args) {
  8. try {
  9. Scanner s=new Scanner(System.in);
  10. Class.forName("com.mysql.jdbc.Driver");
  11. Connection con=DriverManager.getConnection("jdbc:mysql://localhost/fila","root","filimon");
  12. PreparedStatement ps=con.prepareStatement("create table ?(? int(4)primary key,? varchar(20),? float(4,2))");
  13. System.out.print("enter the table name to create: ");
  14. String name=s.nextLine();
  15. ps.setString(1, name);
  16. System.out.print("enter the primarykey column name: ");
  17. String priname=s.nextLine();
  18. ps.setString(2, priname);
  19. System.out.print("enter the second column name: ");
  20. String secname=s.nextLine();
  21. ps.setString(3, secname);
  22. System.out.print("enter the third column name: ");
  23. String thrname=s.nextLine();
  24. ps.setString(4, thrname);
  25. int i=ps.executeUpdate();
  26. System.out.println(i+" table created");
  27. ps.close();
  28. con.close();
  29. s.close();
  30. } catch (Exception e) {
  31. System.err.println(e);
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement