aman0711
asked on
No suitable driver error
Hi Experts,
I have the following code that parses an XML file and stores it in an Oracle DB.
Whenever I am trying to run this code, I am getting the error:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.get Connection (DriverMan ager.java: 592)
at java.sql.DriverManager.get Connection (DriverMan ager.java: 196)
I have kept Xerces Jar and ojdbc14.jar in my classpath.
I have the following code that parses an XML file and stores it in an Oracle DB.
Whenever I am trying to run this code, I am getting the error:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.get
at java.sql.DriverManager.get
I have kept Xerces Jar and ojdbc14.jar in my classpath.
package com.si.keyNote;
import java.io.*;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import java.sql.*;
import javax.sql.*;
import java.util.*;
public class AgentAttributesReader {
String url = "jdbc:oracle:thin:@abc.xyz.com:1522:omft01";
String user = "user";
String pwd = "pass";
public static void main(String[] args) {
try {
String xmlfile ="C:"+File.separator+"KeyNoteDump"+File.separator+"XMLparser"+File.separator+"web"+File.separator+"20090312_0000.xml";
File file = new File(xmlfile);
if (file.exists()){
//SAX-implementation:
SAXParserFactory factory = SAXParserFactory.newInstance();
// Create SAX-parser
SAXParser parser = factory.newSAXParser();
//System.out.println("Slno:\t" +"Name:\t" + "Value:");
//Define a handler
SaxHandler handler = new SaxHandler();
// Parse the xml document
parser.parse(file, handler);
}
else{
System.out.println("File not found!");
}
}
catch (Exception e) {
e.printStackTrace();
}
}
private static class SaxHandler extends DefaultHandler {
public void startElement(String uri, String localName, String qName,
Attributes attrs) throws SAXParseException,SAXException {
String Sql="";
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("url","user","pwd");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/* GETS ALL THE ATTRIBUTES OF AGENT_META_DATA */
if (qName.equals("AGENT_META_DATA")) {
try{
// System.out.println( conn );
PreparedStatement pstmt = null;
Sql= "insert into apm.agent_meta_data1 (AGENT_ID, AGENT_INSTANCE_ID, IP_ADDR, BACKBONE, CITY, COUNTRY, Weight) values (?,?,?,?,?,?,?)";
pstmt = conn.prepareStatement(Sql);
pstmt.setInt(1,new Integer(attrs.getValue("agent_id")));
pstmt.setInt(2,new Integer(attrs.getValue("instance_id")));
pstmt.setString(3,attrs.getValue("ip"));
pstmt.setString(4,attrs.getValue("backbone"));
pstmt.setString(5,attrs.getValue("city"));
pstmt.setString(6,attrs.getValue("country"));
pstmt.setString(7,attrs.getValue("weight"));
pstmt.execute();
pstmt.close();
conn.close();
conn = null;
//System.out.println( "theconnection is closed "+conn );
}catch(Exception sq){
sq.getMessage();
}
}/**/
}
}
}
Are you able to print your classpath here, so that I can see what it is?
ASKER
Hi Warturtle,
I am very new to all this. Could you please tell me how??
will this code help me getting classpath
I am very new to all this. Could you please tell me how??
will this code help me getting classpath
import java.net.URL;
import java.net.URLClassLoader;
public class PrintClasspath {
public static void main(String[] args) {
//Get the System Classloader
ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader();
//Get the URLs
URL[] urls = ((URLClassLoader)sysClassLoader).getURLs();
for(int i=0; i< urls.length; i++)
{
System.out.println(urls[i].getFile());
}
}
}
Open a command prompt and type:
echo %classpath%
ASKER
Please correct me if I am wrong, i am doing all this RAD 7.0 , so running echo %classpath% on command prompt, wont fetch anything useful, right?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi wasturtle,
Thanks for the quick response. I already did the steps you suggested me. both files are in classpath.
I have attached the snap shot of folder hierarchy.
project-folder.PNG
Thanks for the quick response. I already did the steps you suggested me. both files are in classpath.
I have attached the snap shot of folder hierarchy.
project-folder.PNG
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hmmm..,
It didnt work. This time a different error.
java.lang.ClassNotFoundExc eption: oracle.jdbc.OracleDrive
at java.lang.Class.forNameImp l(Native Method)
at java.lang.Class.forName(Cl ass.java:1 30)
at com.si.keyNote.AgentAttrib utesReader $SaxHandle r.startEle ment(Agent Attributes Reader.jav a:51)
at org.apache.xerces.parsers. AbstractSA XParser.st artElement (Unknown Source)
at org.apache.xerces.impl.XML DocumentFr agmentScan nerImpl.sc anStartEle ment(Unkno wn Source)
at org.apache.xerces.impl.XML DocumentFr agmentScan nerImpl$Fr agmentCont entDispatc her.dispat ch(Unknown Source)
It didnt work. This time a different error.
java.lang.ClassNotFoundExc
at java.lang.Class.forNameImp
at java.lang.Class.forName(Cl
at com.si.keyNote.AgentAttrib
at org.apache.xerces.parsers.
at org.apache.xerces.impl.XML
at org.apache.xerces.impl.XML
You are missing an alpabet 'r' at the end of the statement it seems. Because its a classnotfoundexception on oracle.jdbc.OracleDrive
Add r or copy and paste this:
Class.forName("oracle.jdbc .OracleDri ver");
Add r or copy and paste this:
Class.forName("oracle.jdbc
ASKER
Ohk, Sorry... stupid mistake :(
back to the same error:
java.sql.SQLException: No suitable driver
back to the same error:
java.sql.SQLException: No suitable driver
Can you please tell me what version of Oracle are you using? 10g Release 1 or Release 2 and what is the JDK version number that you are using?
ASKER
Not sure, about Release 1 or 2.
this is what i see in my tool
Oracle
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
Oracle JDBC driver
9.2.0.4.0
Current profile: generic
Current facade: oracle
and Jdk 1.4
this is what i see in my tool
Oracle
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
Oracle JDBC driver
9.2.0.4.0
Current profile: generic
Current facade: oracle
and Jdk 1.4
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am sorry warturtle,
I gave you enough trouble. Downloaded a fresh copy of ojdbc.jar and still getting the error :(
java.sql.SQLException: No suitable driver
I gave you enough trouble. Downloaded a fresh copy of ojdbc.jar and still getting the error :(
java.sql.SQLException: No suitable driver
Don't worry about that... I just saw that the url is "jdbc:oracle:thin:@abc.xyz.com:1522:omft01" is that the real url or you need to put the name of the server that you are trying to access??
Try that and let me know, how it goes.
Try that and let me know, how it goes.
ASKER
No I just have this url on EE.
I am using the correct one in my code. :(
I am using the correct one in my code. :(
Hmm... the only thing that I can think of is the URL itself. Try this new format:
jdbc:oracle:thin://abc.xyz .com:1522/ omft01
jdbc:oracle:thin://abc.xyz
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
wow ,, I am so sorry.. I kept you on this for such a silly mistake :-)
My apologies.
Thank you so much
My apologies.
Thank you so much
ASKER
oops, I didnt see it was you objects :-)
Sorry... lol
Sorry... lol
Hahahaa.... that was good observation, objects.
ASKER
Thank you folks :)