sai Narayan

Greenhorn
+ Follow
since Aug 16, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sai Narayan

Hi Friends,
I am have an ASCII text file containing records.I am reading one record at a time using
BufferedReader.readLine();
Then i am reading each dataitem into a StringBuffer from the record as there is a delimiter present after each dataitem.
Now i am unable to typecast the dataitem with that of the field in the database?

here is my code:

import java.sql.Date;
import java.util.*;
import java.io.*;

public class asciitojava {
public static void main(String[] args) throws FileNotFoundException,IOException {

String filename="C:\\javaAbc\\abc.txt";
FileInputStream fis = new FileInputStream(filename);
BufferedReader in = new BufferedReader(new FileReader(filename));
String str;
while ((str = in.readLine()) != null)
{
StringBuffer st = new StringBuffer(str);
System.out.println("\nstr="+str);
StringBuffer word = new StringBuffer();
for(int j=0;j<=str.length();j++)
{


if(j<str.length())
if( (st.charAt(j)!='~'))
{
word.append(st.charAt(j));
}
else
{
System.out.println("word="+word);
word = new StringBuffer();
}
if(j==str.length())
System.out.println("word="+word);
}
}
in.close();

}
}


Please help..
15 years ago
Hi Friends,
I am planning to take the XML certification can you please suggest some good reference books or links for preparation.
Thanks.
Hi friends.
I am trying to import an XML file to Mysql database.Can anybody body please how can i map the xmldata along with datatypes of the columns in the database and how can i import the whole data.
Please help.
Thanks.
Hi Madhav,
here is my classpath and JAVA_HOME:-
C:\>echo %classpath%
C:\Program Files\Altova\xmlspy\XMLSpyInterface.jar;C:\shanker\java\jarfiles\j2ee
.jar;C:\shanker\java\javaprograms12\classes12.jar;C:\Tomcat 5.0\webapps\chapter01\WEB-INF\lib\classes12.jar;C:\shanker\java\jarfiles;C:\WebSphere\AppServer\bin;
C:\shanker\junit3.8.1\junit.jar;C:\shanker\Xerces-J-bin.2.6.2\xerces-2_6_2\Xerce
sSamples.jar;C:\shanker\xmlfiles\jaxp.jar;C:\shanker\xmlfiles\parser.jar;C:\shan
ker\xmlfiles\xalan.jar;C:\shanker\xmlfiles\saxprog;C:\j2sdk1.4.2_04\lib;C:\j2sdk
1.4.2_04\lib\org\apache\crimson\jaxp

C:\>echo %JAVA_HOME%
C:\j2sdk1.4.2_04\lib
Hi Madhav,
Actually i am trying to run the above program.so as per our discussion i have added JAVA_HOME\lib in my classpath.even then i an getting the following error.can you please help me out.I have really got tired of seeing this error.
error:-
C:\shanker\xmlfiles\saxprog>java BooksLibrary
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/crimson/ja
xp/SAXParserFactoryImpl (wrong name: com/macromedia/crimson/jaxp/SAXParserFactor
yImpl)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:493)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:11
1)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(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:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:
117)
at BooksLibrary.main(BooksLibrary.java:20)
Hi madhav,
I have set all the classpath as per ur guidance.even then my program is giving error .can you please help.
program:-
/*com and org folders are sitting in the folder where my program is residing and i have also set the currrent folder in my classpath*/

import java.io.*;

import org.xml.sax.*;
import org.apache.crimson.jaxp.*;
import com.macromedia.crimson.jaxp.*;

import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;

public class BooksLibrary extends HandlerBase
{
protected static final String XML_FILE_NAME = "C:\\Shanker\\xmlfiles\\saxprog\\library1.xml";

public static void main (String argv [])
{
// Use the default (non-validating) parser
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
// Set up output stream
out = new OutputStreamWriter (System.out, "UTF8");

// Parse the input
SAXParser saxParser = factory.newSAXParser();
saxParser.parse( new File(XML_FILE_NAME), new BooksLibrary() );

} catch (Throwable t) {
t.printStackTrace ();
}
System.exit (0);
}

static private Writer out;

//===========================================================
// Methods in SAX DocumentHandler
//===========================================================

public void startDocument ()
throws SAXException
{
showData ("<?xml version='1.0' encoding='UTF-8'?>");
newLine();
}

public void endDocument ()
throws SAXException
{
try {
newLine();
out.flush ();
} catch (IOException e) {
throw new SAXException ("I/O error", e);
}
}

public void startElement (String name, AttributeList attrs)
throws SAXException
{
showData ("<"+name);
if (attrs != null) {
for (int i = 0; i < attrs.getLength (); i++) {
showData (" ");
showData (attrs.getName(i)+"=\""+attrs.getValue (i)+"\"");
}
}
showData (">");
}

public void endElement (String name)
throws SAXException
{
showData ("</"+name+">");
}

public void characters (char buf [], int offset, int len)
throws SAXException
{
String s = new String(buf, offset, len);
showData (s);
}

//===========================================================
// Helpers Methods
//===========================================================

// Wrap I/O exceptions in SAX exceptions, to
// suit handler signature requirements
private void showData (String s)
throws SAXException
{
try {
out.write (s);
out.flush ();
} catch (IOException e) {
throw new SAXException ("I/O error", e);
}
}

// Start a new line
private void newLine ()
throws SAXException
{
String lineEnd = System.getProperty("line.separator");
try {
out.write (lineEnd);
} catch (IOException e) {
throw new SAXException ("I/O error", e);
}
}
}


Error:-
C:\shanker\xmlfiles\saxprog>java BooksLibrary
Exception in thread "main" java.lang.NoClassDefFoundError: org/xml/sax/SAXNo
ognizedException
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java:237)
at javax.xml.parsers.FactoryFinder.newInstance(Unknown Source)
at javax.xml.parsers.FactoryFinder.find(Unknown Source)
at javax.xml.parsers.SAXParserFactory.newInstance(Unknown Source)
at BooksLibrary.main(BooksLibrary.java:20)
hi friends,
i am getting the following error while running my program.
program:-


import java.io.*;

import org.xml.sax.*;
import org.apache.crimson.jaxp.SAXParserFactoryImpl;


import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;

public class BooksLibrary extends HandlerBase
{
protected static final String XML_FILE_NAME = "C:\\Shanker\\xmlfiles\\saxprog\\library1.xml";

public static void main (String argv [])
{
// Use the default (non-validating) parser
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
// Set up output stream
out = new OutputStreamWriter (System.out, "UTF8");

// Parse the input
SAXParser saxParser = factory.newSAXParser();
saxParser.parse( new File(XML_FILE_NAME), new BooksLibrary() );

} catch (Throwable t) {
t.printStackTrace ();
}
System.exit (0);
}

static private Writer out;

//===========================================================
// Methods in SAX DocumentHandler
//===========================================================

public void startDocument ()
throws SAXException
{
showData ("<?xml version='1.0' encoding='UTF-8'?>");
newLine();
}

public void endDocument ()
throws SAXException
{
try {
newLine();
out.flush ();
} catch (IOException e) {
throw new SAXException ("I/O error", e);
}
}

public void startElement (String name, AttributeList attrs)
throws SAXException
{
showData ("<"+name);
if (attrs != null) {
for (int i = 0; i < attrs.getLength (); i++) {
showData (" ");
showData (attrs.getName(i)+"=\""+attrs.getValue (i)+"\"");
}
}
showData (">");
}

public void endElement (String name)
throws SAXException
{
showData ("</"+name+">");
}

public void characters (char buf [], int offset, int len)
throws SAXException
{
String s = new String(buf, offset, len);
showData (s);
}

//===========================================================
// Helpers Methods
//===========================================================

// Wrap I/O exceptions in SAX exceptions, to
// suit handler signature requirements
private void showData (String s)
throws SAXException
{
try {
out.write (s);
out.flush ();
} catch (IOException e) {
throw new SAXException ("I/O error", e);
}
}

// Start a new line
private void newLine ()
throws SAXException
{
String lineEnd = System.getProperty("line.separator");
try {
out.write (lineEnd);
} catch (IOException e) {
throw new SAXException ("I/O error", e);
}
}
}


Error:
C:\shanker\xmlfiles>java -Dorg.xml.sax.driver=org.apache.xerces.parsers.SAXParse
r BooksLibrary
Exception in thread "main" javax.xml.parsers.FactoryConfigurationError: java.lan
g.ClassNotFoundException: org.apache.crimson.jaxp.SAXParserFactoryImpl
at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:
120)
at BooksLibrary.main(BooksLibrary.java:18)
[ November 06, 2004: Message edited by: sai Narayan ]
Hi Sathi,
You can go though www.w3schools.com .It gives a lot of information regarding xml.
[ November 05, 2004: Message edited by: sai Narayan ]
hi datatreya,
i have jsdk1.4.i tried using javac filename -deprecation but even then i am getting 3 warnings .when i try to run then i am getting an error saying NoClassDefFoundError org/sax/handlerBase not found.
can you please help.
thanks
hi friends ,
i am new to xml.i am trying to run a sax parser program and i am getting some errors.can you please help:-

Java file:-



xml file:-


Warnings while compiling:-
C:\shanker\xmlfiles>javac -deprecation BooksLibrary.java
BooksLibrary.java:18: warning: org.xml.sax.HandlerBase in org.xml.sax has been d
eprecated
public class BooksLibrary extends HandlerBase
^
BooksLibrary.java:64: warning: org.xml.sax.AttributeList in org.xml.sax has been
deprecated
public void startElement (String name, AttributeList attrs)
^
BooksLibrary.java:64: warning: org.xml.sax.AttributeList in org.xml.sax has been
deprecated
public void startElement (String name, AttributeList attrs)
^
3 warnings

Errors while trying to run the program:-
C:\shanker\xmlfiles>java BooksLibrary
Exception in thread "main" java.lang.NoClassDefFoundError: org/xml/sax/HandlerBa
se
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:493)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:11
1)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(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:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)

Please help
thanks.



Edit Comment:
When posting code, please use the [ code ] [ / code ] tags without the
spaces. Thanks.

- m
[ November 04, 2004: Message edited by: Madhav Lakkapragada ]
hi friends ,
i have downloaded eclipse-SDK-3.0.1-win32.zip from www.eclipse.org .then i extracted all the files and am trying to start eclipse but i am getting the following error Please Help:-

!SESSION Oct 20, 2004 15:55:55.359 ---------------------------------------------
eclipse.buildId=M200409161125
java.version=1.3.1_02
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US

!ENTRY org.eclipse.osgi Oct 20, 2004 15:55:55.359
!MESSAGE Error registering XML parser services.
!STACK 0
java.lang.ClassNotFoundException: javax.xml.parsers.SAXParserFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at org.eclipse.core.runtime.adaptor.EclipseAdaptor.registerEndorsedXMLParser(EclipseAdaptor.java:272)
at org.eclipse.core.runtime.adaptor.EclipseAdaptor.frameworkStart(EclipseAdaptor.java:253)
at org.eclipse.osgi.framework.internal.core.SystemBundleActivator.start(SystemBundleActivator.java:61)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:958)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:954)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:937)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:553)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:477)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:273)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.launch(StartLevelManager.java:243)
at org.eclipse.osgi.framework.internal.core.SystemBundle.resume(SystemBundle.java:166)
at org.eclipse.osgi.framework.internal.core.Framework.launch(Framework.java:425)
at org.eclipse.osgi.framework.internal.core.OSGi.launch(OSGi.java:51)
at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:216)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:127)
at java.lang.reflect.Method.invoke(Native Method)
at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
at org.eclipse.core.launcher.Main.run(Main.java:704)
at org.eclipse.core.launcher.Main.main(Main.java:688)

!ENTRY org.eclipse.osgi Oct 20, 2004 15:55:55.421
!MESSAGE Startup error
!STACK 1
java.lang.NoClassDefFoundError: org/xml/sax/helpers/DefaultHandler
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:493)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(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:299)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at org.eclipse.core.runtime.adaptor.PluginConverterImpl.parsePluginInfo(PluginConverterImpl.java:557)
at org.eclipse.core.runtime.adaptor.PluginConverterImpl.fillPluginInfo(PluginConverterImpl.java:111)
at org.eclipse.core.runtime.adaptor.PluginConverterImpl.convertManifest(PluginConverterImpl.java:660)
at org.eclipse.core.runtime.adaptor.EclipseBundleData.generateManifest(EclipseBundleData.java:233)
at org.eclipse.core.runtime.adaptor.EclipseBundleData.loadManifest(EclipseBundleData.java:191)
at org.eclipse.core.runtime.adaptor.EclipseBundleData.getManifest(EclipseBundleData.java:159)
at org.eclipse.core.runtime.adaptor.EclipseBundleData.loadFromManifest(EclipseBundleData.java:280)
at org.eclipse.osgi.framework.internal.defaultadaptor.DefaultBundleData.initializeNewBundle(DefaultBundleData.java:77)
at org.eclipse.osgi.framework.internal.defaultadaptor.DefaultAdaptor$1.begin(DefaultAdaptor.java:451)
at org.eclipse.osgi.framework.internal.core.Framework.installWorkerPrivileged(Framework.java:746)
at org.eclipse.osgi.framework.internal.core.Framework$2.run(Framework.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.Framework.installWorker(Framework.java:715)
at org.eclipse.osgi.framework.internal.core.Framework.installBundle(Framework.java:659)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.installBundle(BundleContextImpl.java:219)
at org.eclipse.core.runtime.adaptor.EclipseStarter.installBundles(EclipseStarter.java:800)
at org.eclipse.core.runtime.adaptor.EclipseStarter.loadBasicBundles(EclipseStarter.java:429)
at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:222)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:127)
at java.lang.reflect.Method.invoke(Native Method)
at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
at org.eclipse.core.launcher.Main.run(Main.java:704)
at org.eclipse.core.launcher.Main.main(Main.java:688)

!ENTRY org.eclipse.osgi Oct 20, 2004 15:55:55.437
!MESSAGE Bundle initial@reference:file:c:/shanker/eclipse-SDK-3.0.1-win32/eclipse/plugins/org.eclipse.core.runtime_3.0.1/ [1] was not resolved.

thanks.
thank you very much my code is compiling.
when i run my code i get the following error:-
code:-
import java.io.* ;
import java.sql.*;
import java.util.*;
import oracle.sql.*;
import oracle.jdbc.*;



class javadbconn{


public static void main(String arg[]) throws java.io.IOException
{

Connection connection = null;
try {
// Load the JDBC driver
Class.forName("oracle.jdbc.driver.OracleDriver");

// Create a connection to the database
connection =

DriverManager.getConnection("jdbc : oracle : oci8:@samit:1521:asid","scott","tiger");


} catch (ClassNotFoundException e) {
// Could not find the database driver
e.printStackTrace();
} catch (SQLException e) {
// Could not connect to the database
e.printStackTrace();

}
}
}

error:-
java.sql.SQLException: ORA-06401: NETCMN: invalid driver designator

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:184)
at oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java:1774)
at oracle.jdbc.oci8.OCIDBAccess.logon(OCIDBAccess.java:462)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:353)

at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja
va:457)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:332)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:177)
at javadbconn.main(javadbconn.java:32)

the client side oracle version is as follows:-
Oracle9i Enterprise Edition Release 9.0.1.5.1 - Production
With the Partitioning option
JServer Release 9.0.1.4.0 - Production


[ October 13, 2004: Message edited by: sai Narayan ]
[ October 13, 2004: Message edited by: sai Narayan ]
hi friends ,
my code has:-
import oracle.sql.*;
import oracle.jdbc.*;

for which i am getting the following errors:-
package oracle.sql does not exist

package oracle.jdbc does not exist

pleas help
thanks
[ October 13, 2004: Message edited by: sai Narayan ]