java


how to get next database string in java?


I have stored some multi-term strings like [john smith, mary jones, mary john albert,..] in database one by one.
how to get next, next string from database?
[already i inserted some strings in DB, again i need to use those string from db and i retrived using stringtokenizer [st1m], then i need check each multi-term string, one by one]
how to check how many times "john" occurs in the database?
[here john is occured 2 times in multi-term string]
what is the use of v[j].trim?
my code is:
stas1.executeUpdate("insert into c_ngram values('"+v[j]+"')");
}
StringTokenizer st1m=new StringTokenizer(v[j],"/");
int i1=0;
String posm1[]=new String[10000];
while(st1m.hasMoreElements())
{
posm1[i1]=st1m.nextToken().replace("/", "").trim();
il++;
int ikm=0;
while(st1m.next()!=null)
{
//===========;
ikm++;
}
here v[j] is the strings in database.
please help me.
thanks in advance.
I'll answer using the same order:
When you are trying to iterate in a string array of strings in a single string, like "One,Two,Three", you can do this in two forms.
The first form is using the method split(","), this method will transform you String in a String[] then you can use a loop to iterate between the elements of your String array:
String x = "One,two,three";
String[] array = x.split(",");
for(String item: array){
System.out.println(item);
}
You can use the StringTokenizer and use iterate between the elements.
StringTokenizer tokens=new StringTokenizer(x,",");
//then you do this iterator
while(tokens.hasMoreElements()){
System.out.println(tokens.nextElement());
}
For your second question, lets consider you are inserting a name for each element.
Lets use a table for example: person(integer id,varchar name) and you are inserting your names from your string like this example below:
String x = "john smith, mary jones, mary john albert";
StringTokenizer tokens=new StringTokenizer(x,",");
//then you do this iterator
while(tokens.hasMoreElements()){
... insert each element.
}
when you want to go to database and locate for example names where contains John use a query using like.
Select p.name from person p where p.name like '%John%';
Using this query the database will try to find in every element and column name the text John.
The third answer the .trim() method removes spaces before the first character and after the last character.
String name = " Ana Maria ";
System.out.println(name.trim());
The response will be Ana Maria;
Look more at
About String: http://docs.oracle.com/javase/7/docs/api/java/lang/String.html
About StringTokenizer: http://docs.oracle.com/javase/7/docs/api/java/util/StringTokenizer.html
About QUERY LIKE operators: http://www.w3schools.com/sql/sql_like.asp

Related Links

Is there a way to get a WAN IP address from a phone based on its phone number?
Error reported by SoundManager
What is the best way to separate double into two parts “integer & fraction” in java
sharing data between threads
Java unicode where to find example N-byte unicode characters
Existing String to Double
Setting an Enum value based on incoming String
Can't figure out the bug in this code
Can we use JAVAFX code inside a SWING code?
Reading the content of web page
resource bundle java
Event click on ListView (extends ListActivity)
Access running java program from shell command
Atomic Operation Vs STM
Play sound file into skype call
Converting between ASCII, Binary, Octal, and Hexadecimal

Categories

HOME
ionic-framework
wso2-am
vbscript
netbeans
oracle11g
c#-4.0
drivers
kde
rdf
v8
google-project-tango
in-app-purchase
android-youtube-api
applepay
maude-system
communication
row
windows-azure-storage
carthage
angular-ui
apache-metamodel
pythonanywhere
google-cloud-speech
jtextfield
ml
captiveportal
phpfox
fopen
neo4j-spatial
xacml
tasklet
siesta-swift
calibre
grails-3.1
windows-dev-center
rotational-matrices
environment-modules
vxworks
jquery-bootgrid
withings
xenforo
ws-security
email-templates
http-live-streaming
node-gyp
turbogears
eclipse-gef
scorm
network-flow
theming
logparser
dotnetzip
tropo
composite-key
typed-lambda-calculus
dtexec
windows-mobile-6.5
mako
linode
eventkit
savon
elements
measures
pcf
transmitfile
mongocsharpdriver
impresspages
markojs
ubuntu-10.04
ios4
independentsoft
historian
freedesktop.org
javax.sound.midi
tcpserver
xna-4.0
lib.web.mvc
streambase
pick
internet-connection
valueconverter
android-2.2-froyo
.aspxauth
gridcontrol
flashvars
free-variable
selected
mt
first-responder
propertyeditor
cascalog
php-parser
heartbeat
disclosure
html-input
forums
swing-app-framework
putchar

Resources

Encrypt Message