• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing table name and table structure during run time?

 
omar salem
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone
I am new to jdbc programming. I am trying to design a jdbc application through wich user will be able to pass table name and table structure during run time. My program would ask the user to pass table name and table fields through the console then it would create the specified table at the target database. I have tried the PreparedStatement interface but could not actually get to the method that would serve the purpose.

I have tried this code :

public void tableCreation()
{
BufferedReader br = new BufferedReader(new(InputStreamReader(System.in)));
System.out.println("Enter Table's Name:");
String tablename = br.readLine();
System.out.println("Enter filed name :");
String field1 = br.readLine();
System.out.println("Enter Filed Size");
int i = Integer.parseInt(br.readLine());

// and so on for the remaining fields.
//Can i use PreparedStatement object for that?
// How would my query to the database look like?

PreparedStatement pst = con.createStatement();
pst.execute(query);
}

Would highly appreciate your help.

Omar Salem
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34863
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Omar,
You'll have to build it up in Java: "select " + fieldName + " from " + table.

Binding variables (the question marks) don't work for table or field names.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic