Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / March 2006

Tip: Looking for answers? Try searching our database.

How to get the info from the database

Thread view: 
learner9@gmail.com - 26 Mar 2006 20:51 GMT
Hi,  iam a newbie.When i use the below code, i was unable to get the
required info from the database. i know there are many errors please
let me know how to rectify them.

import javax.xml.stream.*;
import javax.xml.stream.events.* ;
import java.io.InputStream;
import java.net.URL;

public class EUtilParseExample {
private static final String urlSearch =
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?";
private static final String urlFetch =
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?";

public static void main(String[] args) {
InputStream input = null;
try {
URL u = new URL (urlSearch + "db=gene&retmax=10000&term=cmyc");
input = u.openStream();

String filename = "";
XMLInputFactory factory = XMLInputFactory.newInstance();

XMLEventReader r = factory.createXMLEventReader(filename, input);
//iterate as long as there are more events on the input stream
while(r.hasNext()) {
XMLEvent e = r.nextEvent();
while (!e.isStartElement() && r.hasNext())
e = r.nextEvent();
if (e.isStartElement() &&
(e.asStartElement().getName().getLocalPart()).equals("Id")) {
getGeneRecord(r.getElementText());

}
}
}

catch (Exception ex) {
System.err.println("Something bad: " + ex);

}

finally {
try {
if (input != null) input.close();

}

catch (Exception ex) {}

}
}

public static void getGeneRecord(String geneid) {
InputStream in = null;
try {
URL u = new URL(urlFetch +"db=gene&rettype=native&termode=xml&id=" +
geneid);
in = u.openStream();

String filename = "";
XMLInputFactory factory = XMLInputFactory.newInstance();

XMLEventReader r = factory.createXMLEventReader(filename, in);
//iterate as long as there are more events on the input stream
while(r.hasNext()) {
XMLEvent e = r.nextEvent();
while (!e.isStartElement() && r.hasNext())
e = r.nextEvent();
if (e.isStartElement() &&
(e.asStartElement().getName().getLocalPart()).equals("Gene-ref_desc"))
{
system.out.println(r.getElementText());

}
}
}

catch (Exception ex) {
system.err.println("Something else bad: " + ex);

}

finally {
try {
in.close();

}

catch (Exception ex) {}

}
}
}

Thanks,
L
jcsnippets.atspace.com - 26 Mar 2006 22:43 GMT
> Hi,  iam a newbie.When i use the below code, i was unable to get the
> required info from the database. i know there are many errors please
> let me know how to rectify them.
<snipped code>

People will be more inclined to answer your question and help you with your
problem if you're more specific as to what problem(s) you are having.

Having said that, I've had a quick look at your code and the first thing I
noticed was the use of system.out and system.err - remember that Java is
Case Sensitive, so that should read System.err and System.out .

Fix those, and run again - maybe these will solve your problem. If not, feel
free to reply, but please include the specific error you are receiving.

Best regards,

JC
--
http://jcsnippets.atspace.com/
a collection of source code, tips and tricks
learner9@gmail.com - 26 Mar 2006 22:53 GMT
Hi, Iam trying to compile and run the above code to get an idea to
write the further code for another database. I fixed that problem, but
still i got the below errors.
EUtilParseExample.java:1: package javax.xml.stream does not exist
import javax.xml.stream.*;
^
EUtilParseExample.java:2: package javax.xml.stream.events does not
exist
import javax.xml.stream.events.* ;
^
EUtilParseExample.java:17: cannot resolve symbol
symbol  : class XMLInputFactory
location: class EUtilParseExample
XMLInputFactory factory = XMLInputFactory.newInstance();
^
EUtilParseExample.java:17: cannot resolve symbol
symbol  : variable XMLInputFactory
location: class EUtilParseExample
XMLInputFactory factory = XMLInputFactory.newInstance();
                         ^
EUtilParseExample.java:19: cannot resolve symbol
symbol  : class XMLEventReader
location: class EUtilParseExample
XMLEventReader r = factory.createXMLEventReader(filename, input);
^
EUtilParseExample.java:22: cannot resolve symbol
symbol  : class XMLEvent
location: class EUtilParseExample
XMLEvent e = r.nextEvent();
^
EUtilParseExample.java:48: cannot resolve symbol
symbol  : class XMLInputFactory
location: class EUtilParseExample
XMLInputFactory factory = XMLInputFactory.newInstance();
^
EUtilParseExample.java:48: cannot resolve symbol
symbol  : variable XMLInputFactory
location: class EUtilParseExample
XMLInputFactory factory = XMLInputFactory.newInstance();
                         ^
EUtilParseExample.java:50: cannot resolve symbol
symbol  : class XMLEventReader
location: class EUtilParseExample
XMLEventReader r = factory.createXMLEventReader(filename, in);
^
EUtilParseExample.java:53: cannot resolve symbol
symbol  : class XMLEvent
location: class EUtilParseExample
XMLEvent e = r.nextEvent();
^
10 errors

Thanks,
L
Bill Karwin - 26 Mar 2006 23:04 GMT
> EUtilParseExample.java:1: package javax.xml.stream does not exist
> import javax.xml.stream.*;

The javax.xml.stream package is part of the Java Web Services Developer
Pack.  It is not included in the J2SE SDK.  Do you have the JWSDP product
installed, and can it be located by your CLASSPATH as you compile?

http://java.sun.com/webservices/jwsdp/

Regards,
Bill K.

"90% of Java issues are classpath issues."
Roedy Green - 27 Mar 2006 04:01 GMT
>The javax.xml.stream package is part of the Java Web Services Developer
>Pack.  It is not included in the J2SE SDK.  Do you have the JWSDP product
>installed, and can it be located by your CLASSPATH as you compile?
>
>http://java.sun.com/webservices/jwsdp/

in general when you can't find a jar, check out
http://mindprod.com/jgloss/wherejars.html
to tell you which jar to look in and where to download the jar.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

learner9@gmail.com - 27 Mar 2006 04:11 GMT
Hello,
 I just have downloaded the jwsdp from the url you mentioned and here
is my path  when I typed in cmd window

C:\Documents and Settings\Administrator>path
PATH=C:\texmf\miktex\bin;C:\MiKTeX\texmf\miktex\bin;C:\Program
Files\Perl\bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\
Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program
Files\Common Files\Roxio Shared\DLLShared;D:\j2sdk1.4.2_04\bin
;C:\Program
Files\Perl\site\lib;C:\MiKTeX\texmf\miktex\bin;C:\texmf\miktex\bin;C:\Sun\j­wsdp-2.0\jwsdp-shared\bin;C:\Sun\jwsdp-2.0\

jwsdp-shared\bin;C:\texmf\miktex\bin;C:\MiKTeX\texmf\miktex\bin;C:\Program

Files\Perl\bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDO
WS\System32\Wbem;C:\Program Files\Microsoft SQL
Server\80\Tools\BINN;C:\Program Files\Common Files\Roxio
Shared\DLLShared;D:\j2sdk
1.4.2_04\bin;C:\Program
Files\Perl\site\lib;C:\MiKTeX\texmf\miktex\bin;C:\texmf\miktex\bin;C:\Sun\j­wsdp-2.0\jwsdp-shared\bin;C:\PR

OGRA~1\COMMON~1\MUVEET~1\030625

in which

D:\j2sdk1.4.2_04\bin; is the java path
and
C:\Sun\jwsdp-2.0\jwsdp-shared\bin; java web services path

but I still get the same error saying that javax.xml.stream doesn't
exist.

I am missing some thing here?

Thanks
-L
learner9@gmail.com - 27 Mar 2006 04:08 GMT
Hello Bill,
 I just have downloaded the jwsdp from the url you mentioned and here
is my path  when I typed in cmd window

C:\Documents and Settings\Administrator>path
PATH=C:\texmf\miktex\bin;C:\MiKTeX\texmf\miktex\bin;C:\Program
Files\Perl\bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\
Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program
Files\Common Files\Roxio Shared\DLLShared;D:\j2sdk1.4.2_04\bin
;C:\Program
Files\Perl\site\lib;C:\MiKTeX\texmf\miktex\bin;C:\texmf\miktex\bin;C:\Sun\jwsdp-2.0\jwsdp-shared\bin;C:\Sun\jwsdp-2.0\
jwsdp-shared\bin;C:\texmf\miktex\bin;C:\MiKTeX\texmf\miktex\bin;C:\Program
Files\Perl\bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDO
WS\System32\Wbem;C:\Program Files\Microsoft SQL
Server\80\Tools\BINN;C:\Program Files\Common Files\Roxio
Shared\DLLShared;D:\j2sdk
1.4.2_04\bin;C:\Program
Files\Perl\site\lib;C:\MiKTeX\texmf\miktex\bin;C:\texmf\miktex\bin;C:\Sun\jwsdp-2.0\jwsdp-shared\bin;C:\PR
OGRA~1\COMMON~1\MUVEET~1\030625

in which

D:\j2sdk1.4.2_04\bin; is the java path
and
C:\Sun\jwsdp-2.0\jwsdp-shared\bin; java web services path

but I still get the same error saying that javax.xml.stream doesn't
exist.

I am missing some thing here?

Thanks
-L
Bill Karwin - 27 Mar 2006 05:58 GMT
> but I still get the same error saying that javax.xml.stream doesn't exist.
>
> I am missing some thing here?

Yes, you are indeed missing something, if you are programming in Java.

The PATH is different from the CLASSPATH.  The former tells the Windows
shell where to find executables.  The latter tells Java where to find
classes and other resources.

There is no sharing of information between the PATH and the CLASSPATH.  They
are two separate animals.

Read this document:
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/classpath.html

Regards,
Bill K.
Roedy Green - 27 Mar 2006 06:27 GMT
>Yes, you are indeed missing something, if you are programming in Java.
>
>The PATH is different from the CLASSPATH.  

see http://mindprod.com/jgloss/path.html
http://mindprod.com/jgloss/classpath.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

learner9@gmail.com - 29 Mar 2006 05:49 GMT
Hello,
  I did add the path to the class path as below

set classpath=C:\Sun\j­­wsdp-2.0\jwsdp-shared\bin

But it still complains about the complains about the
EUtilParseExample.java:2: package javax.xml.stream.events does not
exist
import javax.xml.stream.events.* ;

Have I done some thing wrong in setting up the class path?

Thanks
-L
^
Roedy Green - 29 Mar 2006 07:01 GMT
>Have I done some thing wrong in setting up the class path?

It is easier to put all the jars you need that you have downloaded in
the ext directories.  see http://mindprod.com/jgloss/classpath.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

learner9@gmail.com - 29 Mar 2006 13:38 GMT
Hello,
  I did add the path to the class path as below

set classpath=C:\Sun\j­­wsdp-2.0\jwsdp-shared\bin

But it still complains about the complains about the
EUtilParseExample.java:2: package javax.xml.stream.events does not
exist
import javax.xml.stream.events.* ;

Have I done some thing wrong in setting up the class path?

Thanks
-L
Cos - 29 Mar 2006 19:01 GMT
Add the location of the appropriate jar files. I'm asuuming they reside
somewhere else, but not in the .../bin directory.

And it's good to RTFM sometimes - some Sun's docs or dummy books

Cos
learner9@gmail.com - 30 Mar 2006 21:23 GMT
I added the location of all the jar files. But still the same
errors!!!!

Thanks,
L
Roedy Green - 27 Mar 2006 00:30 GMT
>URL u = new URL (urlSearch + "db=gene&retmax=10000&term=cmyc");
>input = u.openStream();

to read from an URL you normally  do an HTTP GET. You have left out
quite a bit.  See http://mindprod.com/applets/fileio.html
for sample code.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.