473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

unable to identify the table in specified database

126 64KB
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
3 2348
Rabbit
12,516 Expert Mod 8TB
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
PreethiGowri
126 64KB
i'm not able to solve this, can you suggest me something
Dec 13 '12 #3
PreethiGowri
126 64KB
i solved it,

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

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

Similar topics

0
by: Jim M | last post by:
For about a year and a half now I have been working in Access 2002 at home and converting to Access 2000 for work (I need both versions). I made a few changes to forms and queries then converted to...
6
by: Jchick | last post by:
Im a newbie with a sql table in a MSDE database that contains fields of CustName, BrokerName, Type, Status. I am trying to write a trigger that does this: 1. When a new record in a table is...
7
by: s w dunn | last post by:
Hello, I am in charge of maintaining a little ACCESS database used by our purchasing department. I need to add some new values to a table, but I can't open the .be database in order to access the...
2
by: prajeeshv | last post by:
Hi Everyone, Have a nice day... I've a problem in SQL Server... I've detached my database from server. But I didn't remember the location of its .mdf (database) file. Now I'm...
1
by: bb nicole | last post by:
Below is my interface for resume which need to post into database... I have did it all in one page and it already can send into database which the table name resume... But my letturer now want me...
1
by: EgoSum | last post by:
I make dataset in c# and after that add the column into table in database. Although I expand dataset with it, app dont recognize added column. It's haped to me several times. What can I do to...
1
by: nafi925 | last post by:
hi all i need some help on my project' i need to get xml string of a table from database to send mail's am currently using a STORED PROCEDURE but am returning a nvarchar(max) value so the length...
1
by: ZZ_Scarab | last post by:
Hi, <I posted this on the microsoft.public.dotnet.framework.aspnet.security newsgroup but before I got a reply this newsgroup has become unavailable!! So I'm posting it here again. Sorry for the...
9
alisyah
by: alisyah | last post by:
is it possible to insert the time table in database?
1
by: anna george | last post by:
hi! i have created a class 'ChangePassword' which is called from 'login' both extending jframe. i'm trying to take a new password from the user and update the savelogin table in database Employ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.