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 / GUI / March 2006

Tip: Looking for answers? Try searching our database.

How to get the info from the database

Thread view: 
L - 26 Mar 2006 20:49 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
Oliver Wong - 29 Mar 2006 22:25 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.

[code snipped]

   What errors are you getting?

   - Oliver


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.