permaculture playing cards*
The moose likes JDBC and the fly likes Passing table name and table structure during run time? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Passing table name and table structure during run time?" Watch "Passing table name and table structure during run time?" New topic
Author

Passing table name and table structure during run time?

omar salem
Ranch Hand

Joined: Aug 22, 2006
Posts: 34
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


Have a sip of Java !!!
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing table name and table structure during run time?
 
Similar Threads
how to upload pdf files to My sql with java
How to move cursor to next row?
Unable to Access mysql database through JNDI.
moving cursors to next row
moving cursor to the next row