Click here to Skip to main content
15,913,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
please help me to solve this problem.

i want to count number of times the specific word occured in database using java?

for example, my database c-ram contains

Words
john smith john, mary jones, mary john albert

[Words is the field name in c-ram table]

i want to check how many times "john" occured in c-ram.

i have checked coding without query too, but i cant find the solution. if i use this below query i get same query as output, also i can't to use integer varible to assign for this query.

             for(int jm=0;jm<ij;jm++)
              { 
             String query1 = null;
              for(int k=0;k<ikm;k++)
              {
              if(word[jm].contains(item1))
                {
                    query1="SELECT COUNT(*) FROM c_ram WHERE Words = item";
                }
help me to get answer with or woithout using query. thanks in advance.
Posted

1 solution

All you need to write a query that should check whether your db contains that specific value, when finds true it will increase a counter value.
Check these queries:
Java MySQL check if value exists in database[^]
 
Share this answer
 
Comments
Deepa131 10-Dec-15 11:06am    
ya i tried that code. but i have got error while running.
my code is
if(word[jm].contains(item1))
{
final String query1="SELECT COUNT(*) FROM c_ram WHERE Words = item1";
final PreparedStatement ps = conn.prepareStatement(query1);
ps.setString(1, item1);
final ResultSet resultSet = ps.executeQuery();
if(resultSet.next()) {
final int count = resultSet.getInt(1);
System.out.println("vkm"+vkm+query1+ "q="+count);
}

it shows error in " final PreparedStatement ps = conn.prepareStatement(query1);"
this line
ridoy 10-Dec-15 12:51pm    
Check your database connection string, is your database connected properly with your code? Do you check that?The exceptions certainly points to the connection problem.
Deepa131 10-Dec-15 13:17pm    
my error :
java.lang.ClassFormatError: Duplicate field name&signature in class file Blog/POS_tag_f11111
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Exception in thread "main" Java Result: 1
Deepa131 10-Dec-15 13:19pm    
and i changed the code
final String query1="SELECT COUNT(*) FROM c_ngram WHERE Words = ?";
like this
so got this error. please tel me how to resolve
ridoy 10-Dec-15 14:51pm    
@Deepa131, check this message " Duplicate field name&signature in class file " from you exception message. Do your database has same field names?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900