• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Passing table name and table structure during run time?

 
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
 
author & internet detective
Posts: 39343
755
Eclipse IDE VI Editor Java
  • 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
Boost this thread!