By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,651 Members | 1,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,651 IT Pros & Developers. It's quick & easy.

unable to identify the table in specified database

100+
P: 126
i have the following code which checks if the table exists in the database, if yes then inserts some values

Expand|Select|Wrap|Line Numbers
  1. String data = "%1:zetakalyam:arjun";
  2. if (data.startsWith("%1")) {
  3. String str = data;
  4. String[] cmd;
  5. String delimiter = "%|\\$|\\:|\\#";
  6. cmd = str.split(delimiter);
  7. System.out.println(cmd.length);
  8. for (int i = 0; i < cmd.length;i++) {
  9. System.out.println("cmd of " +i+ "=" +cmd[i]);
  10.                    }
  11. Connection con = null;
  12. try{
  13.  Class.forName("com.mysql.jdbc.Driver");
  14.   String conURL = "jdbc:mysql://localhost/employee";
  15.   con = DriverManager.getConnection(conURL, "root", "root");
  16.   DatabaseMetaData dbm = con.getMetaData();
  17.   ResultSet tables = dbm.getTables(null, null, "+cmd[2]+", null);
  18.  if (tables.next()) { //if table exists
  19. Statement st = con.createStatement();
  20. String query = "insert into " + cmd[2] + " 
  21. (name,employee_id,date,logout) select 
  22. name,employee_id,curdate(),'0' from tbi where name = '" + cmd[3] + "'";
  23.   ResultSet rs1 = st.executeQuery(query); 
  24.                 }
  25. else{
  26.  
  27.  System.out.println("table does not exists");
  28.               }
  29.               }
  30. catch(ClassNotFoundException | SQLException e){
  31.  
  32.               }

i have a database called employee, which contains a table zetakalyam But, i get the result as table does not exists:(

i have checked the database and it shows the table in its list
Dec 12 '12 #1
Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,421
On line 17, I would check the value that you're passing because I don't think it's passing what you think it's passing.
Dec 12 '12 #2

100+
P: 126
i'm not able to solve this, can you suggest me something
Dec 13 '12 #3

100+
P: 126
i solved it,

i had to write just cmd[2] instead of "+cmd[2]+"
Dec 13 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.