Exception in thread "main" java.sql.SQLException:
when i run the JdbcTest.java program happen this:
C:\temp>javac JdbcTest.java
C:\temp>java -cp .;C:\oracle\ora81\jdbc\lib\classes111.zip JdbcTest
Exception in thread "main" java.sql.SQLException: Eccezione IO: Connection refus
ed(DESCRIPTION=(TMP=)(VSNNUM=135290880)(ERR=12500)(ERROR_STACK=(ERROR=(CODE=1250
0)(EMFI=4))(ERROR=(CODE=12560)(EMFI=4))(ERROR=(CODE=530)(EMFI=4))(ERROR=(BUF='32
-bit Windows Error: 2: No such file or directory'))))
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja
va)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at JdbcTest.main(JdbcTest.java:12)
the sample code is this>
import java.sql.*;
class JdbcTest {
public static void main (String args []) throws SQLException {
// Load Oracle driver
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
// Connect to the local database
Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@pcserver:1521:PIRELLI",
"vetture", "vetture");
// Query the employee names
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("select a from pippo");
// Print the name out
while (rset.next ())
System.out.println (rset.getString (1));
-------please halp me
what u say is correct becouse if i use another db-oracle
and for use it i change the host, the port and sid, it works.
DriverManager.getConnection ("jdbc:oracle:thin:@ULISSE:1651:APIS",
"vetture", "vetture");
and in this case the database is on another machine.
if i try with :
DriverManager.getConnection ("jdbc:oracle:thin:@pcserver:1521:PIRELLI",
"vetture", "vetture");
doesn't work, but i can read from the database with another product TOAD, so this meand the DB service is running, I can't undestand.
In any case thanks becouse now i know that the problem is not about classpath or sqlstatement, but is only about configuration and service.
Similar Messages
-
Hi Everyone,
I am Using This Code to read the Mail from server and inserting those into database but i am getting error like
import java.io.*;
import java.util.*;
import javax.mail.*;
import java.sql.*;
public class ReadMail_OLD {
static StringBuffer s= new StringBuffer();
static StringBuffer s1= new StringBuffer();
public static void main(String args[]) throws Exception {
String host = "***.****.co.in";
String user = "***@***.**.**";
String password = "******";
String Message_2000 = new String();
String Message_2001 = new String();
Connection conn;
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@1.2.3.5:1050:abcgdb", "abc", "efg");
Statement stm = conn.createStatement();
String strsql = "insert into READ_MAIL_MSG (MESSAGE_ID,SENT_DATE,MAIL_FROM,MAIL_TO,MAIL_SUBJECT,MESSAGE) values (" ;
// Get system properties
Properties properties = System.getProperties();
// Get the default Session object.
Session session = Session.getDefaultInstance(properties);
// Get a Store object that implements the specified protocol.
Store store = session.getStore("pop3");
//Connect to the current host using the specified username and password.
store.connect(host, user, password);
//Create a Folder object corresponding to the given name.
Folder folder = store.getFolder("inbox");
// Open the Folder.
folder.open(Folder.READ_ONLY);
Message[] message = folder.getMessages();
// Display message.
for (int i = 0; i < message.length; i++)
//System.out.println("------------ Message " + (i + 1) + " ------------");
//System.out.println("SentDate : " + message.getSentDate());
//System.out.println("From : " + message[i].getFrom()[0]);
//System.out.println("Subject : " + message[i].getSubject());
//System.out.print("Message : ");
InputStream stream = message[i].getInputStream();
int j = 0;
Message_2000 = "";
Message_2001 = "";
while(stream.available()>0 && j < 500)
// read the byte and convert the integer to character
s.append((char) stream.read());
j = j+1;
Message_2000 = s.toString();
Message_2001 = Message_2000.replace("'"," ");
System.out.println(strsql+"'"+(i + 1)+"','"+message[i].getSentDate()+"','"+message[i].getFrom()[0]+"','***@***.co.in','"+message[i].getSubject()+"','"+s.toString()+"')");
stm.execute(strsql+"'"+(i + 1)+"','"+message[i].getSentDate()+"','"+message[i].getFrom()[0]+"','***@****.co.in','"+message[i].getSubject()+"','"+Message_2001+"')");
folder.close(true);
store.close();
when i execute this some messages get inserted into table but for some messages
Exception in thread "main" java.sql.SQLException: ORA-01704: string literal too long
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:582)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1983)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1141)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2149)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2032)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2894)
at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:942)
at ReadMail_OLD.main(ReadMail_OLD.java:64)
Edited by: 997089 on May 1, 2013 9:29 PM
Edited by: 997089 on May 1, 2013 9:30 PMHi All,
Thanks for Your Reply .
I got the answer i have made a mistake in loop after every iteration i have not cleared the stringBuffer Varaible so the after one or two iteration it givesthe error.
import java.io.*;
import java.util.*;
import javax.mail.*;
import java.sql.*;
public class ReadMail_OLD {
static StringBuffer s= new StringBuffer();
static StringBuffer s1= new StringBuffer();
public static void main(String args[]) throws Exception {
String host = "***.****.co.in";
String user = "***@***.**.**";
String password = "******";
String Message_2000 = new String();
String Message_2001 = new String();
Connection conn;
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@1.2.3.5:1050:abcgdb", "abc", "efg");
Statement stm = conn.createStatement();
String strsql = "insert into READ_MAIL_MSG (MESSAGE_ID,SENT_DATE,MAIL_FROM,MAIL_TO,MAIL_SUBJECT,MESSAGE) values (" ;
// Get system properties
Properties properties = System.getProperties();
// Get the default Session object.
Session session = Session.getDefaultInstance(properties);
// Get a Store object that implements the specified protocol.
Store store = session.getStore("pop3");
//Connect to the current host using the specified username and password.
store.connect(host, user, password);
//Create a Folder object corresponding to the given name.
Folder folder = store.getFolder("inbox");
// Open the Folder.
folder.open(Folder.READ_ONLY);
Message[] message = folder.getMessages();
// Display message.
for (int i = 0; i < message.length; i++)
//System.out.println("------------ Message " + (i + 1) + " ------------");
//System.out.println("SentDate : " + message.getSentDate());
//System.out.println("From : " + message.getFrom()[0]);
//System.out.println("Subject : " + message.getSubject());
//System.out.print("Message : ");
InputStream stream = message.getInputStream();
int j = 0;
Message_2000 = "";
Message_2001 = "";
while(stream.available()>0 && j < 500)
// read the byte and convert the integer to character
s.append((char) stream.read());
j = j+1;
Message_2000 = s.toString();
Message_2001 = Message_2000.replace("'"," ");
System.out.println(strsql+"'"+(i + 1)+"','"message.getSentDate()"','"message.getFrom()[0]"','***@****.co.in','"message.getSubject()"','"s.toString()"')");
stm.execute(strsql+"'"+(i + 1)+"','"message.getSentDate()"','"message.getFrom()[0]"','***@****.co.in','"message.getSubject()"','"Message_2001"')");
s.delete(0, s.length());
folder.close(true);
store.close();
Thanks for Reply
Edited by: 997089 on May 1, 2013 9:28 PM
Edited by: 997089 on May 1, 2013 9:30 PM -
Exception in thread "main" java.sql.SQLException: ORA-00604
Just tried to compile the code "Example 2-1 Determing the JDBC Driver Version" from "2day plus Java Developoer Guide"..
import java.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;
public class JDBCVersion
public static void main (String args[]) throws SQLException
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:hr/hr@localhost:1521/XE");
Connection conn = ods.getConnection();
// Create Oracle DatabaseMetaData object
DatabaseMetaData meta = conn.getMetaData();
// gets driver info:
System.out.println("JDBC driver version is " + meta.getDriverVersion());
So, when I have to execute this programm:
Exception in thread "main" java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1
ORA-12705: Cannot access NLS data files or invalid environment specified
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:283)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:278)
at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOauth(T4CTTIoauthenticate.java:785)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:362)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:297)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:221)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:165)
at oracle.JDBCVersion.main(JDBCVersion.java:12)
Pls, help me w/that. TNX.Hi,
I remember it also doesn't work for me. Try this:
DriverManager.getConnection("jdbc:oracle:thin:@<mc-name>:<port-no>:<sid>", "scott", "tiger");
Kuba -
Exception in thread "main" java.sql.SQLException: Io exception: Connection
Hello
I created a java program to connect to a oracle database 10g
I got the following error:
Exception in thread "main" java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=153093632)(ERR=12514)(ERROR_STACK=(ERROR=(CODE=12514)(EMFI=4))))
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:418)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:521)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:325)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at dbAccess.main(dbAccess.java:10)
here the code
import java.sql.*;
class dbAccess {
public static void main (String args []) throws SQLException
if (args.length<=0) {System.out.println("You need to provide the user and password");System.exit(0);}
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@dathvader2003:1521:orcl", args[0], args[1]);
// @machineName:port:SID, userid, password
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
while (rset.next())
System.out.println (rset.getString(1)); // Print col 1
stmt.close();
Any helps?
Many thanksThis is the exactly code
import java.io.PrintStream;
import java.sql.*;
import oracle.jdbc.driver.OracleDriver;
class dbAccess
dbAccess()
public static void main(String args[])
throws SQLException
if(args.length <= 0)
System.out.println("You need to provide the user and password");
System.exit(0);
DriverManager.registerDriver(new OracleDriver());
Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@dathvader2003:1521:orcl", args[0], args[1]);
Statement statement = connection.createStatement();
for(ResultSet resultset = statement.executeQuery("select BANNER from SYS.V_$VERSION"); resultset.next(); System.out.println(resultset.getString(1)));
statement.close();
} -
Exception in thread "main" java.sql.SQLRecoverableException: Io exception:
When applying the 6678700 (12.1.1) Upgrade patch i am getting the below error.
Raised Sev 2 SR with Oracle and they requested to change the following following paramter and bounce the DB as well Listener and re-start the patch. Did the same but no luck. Please let us know if anyone faced similar issue and fix for this issue
Edit the sqlnet.ora and set the parameter:
SQLNET.INBOUND_CONNECT_TIME=0
Edit the listener.ora and set the parameter
connect_timeout_ = 0
============================================================================================================================================
adjava oracle.apps.ad.worker.AdJavaWorker "(DESCRIPTION=(LOAD_BALANCE=YES)(FAILOVER=YES)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=ihr45r)(PORT=31101)))(CONN
ECT_DATA=(SID=IHR45R)))" APPS ***** thin 4 /home/apps/ora_hr/IHR45R/apps/apps_st/appl/admin/adUtilMapNew.txt
Copyright (c) 2002 Oracle Corporation
Redwood Shores, California, USA
AD Java
Version 12.0.0
NOTE: You may not use this utility for custom development
unless you have written permission from Oracle Corporation.
Reading product information from file...
Reading language and territory information from file...
Reading language information from applUS.txt ...
Temporarily resetting CLASSPATH to:
"/home/apps/ora_hr/IHR45R/apps/apps_st/appl/ad/12.0.0/java/adjava.zip:/home/apps/ora_hr/IHR45R/apps/tech_st/10.1.3/appsutil/jdk/lib/dt.jar:/home/apps/ora_h
r/IHR45R/apps/tech_st/10.1.3/appsutil/jdk/lib/tools.jar:/home/apps/ora_hr/IHR45R/apps/tech_st/10.1.3/appsutil/jdk/jre/lib/rt.jar:/home/apps/ora_hr/IHR45R/app
s/apps_st/comn/java/lib/appsborg.zip:/home/apps/ora_hr/IHR45R/apps/tech_st/10.1.2/forms/java:/home/apps/ora_hr/IHR45R/apps/tech_st/10.1.2/forms/java/frmall.j
ar:/home/apps/ora_hr/IHR45R/apps/tech_st/10.1.2/jlib/ewt3.jar:/home/apps/ora_hr/IHR45R/apps/tech_st/10.1.2/j2ee/OC4J_BI_Forms/applications/formsapp/formsweb/
WEB-INF/lib/frmsrv.jar:/home/apps/ora_hr/IHR45R/apps/apps_st/comn/java/classes"
Calling /home/apps/ora_hr/IHR45R/apps/tech_st/10.1.3/appsutil/jdk/jre/bin/java ...
Exception in thread "main" java.sql.SQLRecoverableException: Io exception: Broken pipe
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:101)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:521)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:418)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:510)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:203)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:510)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at oracle.apps.ad.worker.AdJavaWorker.getAppsConnection(AdJavaWorker.java:1036)
at oracle.apps.ad.worker.AdJavaWorker.main(AdJavaWorker.java:276)
Caused by: java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:103)
at java.net.SocketOutputStream.write(SocketOutputStream.java:147)
at oracle.net.ns.DataPacket.send(DataPacket.java:150)
at oracle.net.ns.NetOutputStream.flush(NetOutputStream.java:180)
at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:169)
at oracle.net.ns.NetInputStream.read(NetInputStream.java:117)
at oracle.net.ns.NetInputStream.read(NetInputStream.java:92)
============================================================================================================================================
Thanks and Regards,
JagadeeshaHi ,
Thanks for our prompt response.
After following Oracle Recommendation same error getting no improvement.
Below is the alert log error.
================================================================================================
Fatal NI connect error 12170.
VERSION INFORMATION:
TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
TCP/IP NT Protocol Adapter for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
Oracle Bequeath NT Protocol Adapter for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
Time: 01-NOV-2012 11:02:37
Tracing not turned on.
Tns error struct:
ns main err code: 12535
TNS-12535: TNS:operation timed out
ns secondary err code: 12606
nt main err code: 0
nt secondary err code: 0
nt OS err code: 0
Client address: (ADDRESS=(PROTOCOL=tcp)(HOST=10.16.0.194)(PORT=61100))
WARNING: inbound connection timed out (ORA-3136)
Thu Nov 01 11:02:45 2012
==============================================================================================
Let me know how to check the processes we have 8 CPU and running with distrubed mode with 32 worker with each server 16.
Let me know what i need to check in the /etc/hosts file.
Thanks,
Jagadeesha -
I know this has been posted repeatedly. However, I have tried all the generic solutions Mine is a little different.
1. I can connect with SQLPLUS to the database. I am on windows XP connecting to Oracle 10g on a Solaris box. So the listener is running.
2. Here is my tnsnames.ora entry which works with SQLPLUS:
I can tnsping this address
SID_NAME =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = IP_NUMBER)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = SID_NAME)
)I am trying to run the following sample code:
* This sample shows how to list all the names from the EMP table
* It uses the JDBC THIN driver. See the same program in the
* oci8 samples directory to see how to use the other drivers.
package basic;
// You need to import the java.sql package to use JDBC
import java.sql.*;
class Employee
public static void main (String args [])
throws SQLException
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as <host>:<port>:<sid>. The example uses the short cut syntax.
String url = "jdbc:oracle:thin:@IP_NAME:1521:SID_NAME";
String userName = "USERNAME";
String password = "PASSWORD";
if (args.length > 0) url = args[0];
if (args.length > 1) userName = args[1];
if (args.length > 2) password = args[2];
//Connection conn =
// DriverManager.getConnection (url, userName, password);
Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=IP_NUMBER:1521)(PORT=1521)))(CONNECT_DATA=(SID=SID_NAME)(SERVER=DEDICATED)))", "USERNAME", "PASSWORD");
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select object_name from user_objects");
// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}I also used the following IP
Connection conn =
DriverManager.getConnection (url, userName, password);Replace the url with
String url = "jdbc:oracle:thin:@IP_NUMBER:1521:SID_NAME"; -
I am getting the following exception described below:
Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Savepoint
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java, Compiled Code)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java, Compiled Code)
at java.net.URLClassLoader.defineClass(URLClassLoader.java, Compiled Code)
at java.net.URLClassLoader.access$1(URLClassLoader.java, Compiled Code)
at java.net.URLClassLoader$1.run(URLClassLoader.java, Compiled Code)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java, Compiled Code)
at java.lang.ClassLoader.loadClass(ClassLoader.java, Compiled Code)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java, Compiled Code)
at java.lang.ClassLoader.loadClass(ClassLoader.java, Compiled Code)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java, Compiled Code)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java, Compiled Code)
at java.sql.DriverManager.getConnection(DriverManager.java, Compiled Code)
at java.sql.DriverManager.getConnection(DriverManager.java, Compiled Code)
at source.UserCompileASLFromPatch.getConnection(UserCompileASLFromPatch.java, Compiled Code)
at source.UserCompileASLFromPatch.initialize(UserCompileASLFromPatch.java, Compiled Code)
at source.UserCompileASLFromPatch.main(UserCompileASLFromPatch.java, Compiled Code)
I am using java version "1.4.2_09" for the JDBC Connection. Is it the version problem or can be a problem specific to the code?hello debdatta
The JVM is unable to find the class. Just check ur driver class whether its included in the class path.
and its not getting the location of the file. The path where ur program is searching the class isnt there. so its the problem with ur path not the program. -
Exception in thread "main" java.lang.NullPointerException error JDeveloper 12c
Hello,
I am trying to call a java stored procedure in java application. I am using ORACLE database and JDeveloper.
I am getting error "Exception in thread "main" java.lang.NullPointerException. I have no idea what have I been doing wrong.
I have a table "Beer" and I want to select all the data out with a stored procedure which I call out of Java app.
I have a java.class file Store_A.java which I have loaded into the ORACLE database with LOADJAVA :
import java.sql.*;
import java.io.*;
public class Store_a {
public static void apskatit ()
throws SQLException
{ String sql =
"SELECT * FROM Beer";
try { Connection conn = DriverManager.getConnection("jdbc:default:connection:");
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rset = pstmt.executeQuery();
rset.close();
pstmt.close();
catch (SQLException e) {System.err.println(e.getMessage());
Then I have created a procedure which I plan to call out in java:
CREATE OR REPLACE PACKAGE Store_a AS
PROCEDURE apskatit;
END Store_a;
CREATE OR REPLACE PACKAGE BODY Store_a AS
PROCEDURE apskatit AS LANGUAGE JAVA
NAME 'Store_a.apskatit()';
END Store_a;
And I have a java file that I have created with JDeveloper 12c:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Class1 {
* @param args
public static void main(String[] args) throws SQLException {
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//Izveidojam savienojumu
conn = DriverManager.getConnection("jdbc.oracle.thin:@localhost:1521", "SYSTEM", "asdasd");
// Izveidojam callable statement
CallableStatement stmt = conn.prepareCall("CALL Store_a.apskatit()");
ResultSet resul = stmt.executeQuery();
while (resul.next()) {
System.out.println(resul.getInt(1) + "\t" + resul.getString(2));
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
When I try to run the java file, I get this error "Exception in thread "main" java.lang.NullPointerException at client.Class1.main(Class1.java:29).
So the line I get error in is "conn.close();"
How to fix this?
Thank you very much in advance.I am trying to call a java stored procedure in java application. I am using ORACLE database and JDeveloper.
I am getting error "Exception in thread "main" java.lang.NullPointerException. I have no idea what have I been doing wrong.
Maybe you haven't read it yet but I told you in your other thread what you were doing wrong and, step by step, how to address the problem.
https://forums.oracle.com/thread/2611124
I'm not going to repeat everything again just this one main piece of advice:
Until you get you code working outside the database don't even bother trying to load it into the DB and create a Java stored procedure.
You are trying to deal with too many different issues at the same time. Unless you solve your primary Java problem by fixing the code outside the DB you will have nothing but problems loading it into the DB.
And just get rid of this line of code - you don't need it anymore and it hasn't been done like that for many years now:
Class.forName("oracle.jdbc.driver.OracleDriver"); -
Hi,
I am new to SQLJ. Now, in my PC (with Win98), I have JDK 1.2 and Oracle 8i (personal edition). I have used Java and Oracle in my PC without any problem. Now, I am going to learn SQLJ in order to create a java program to access Oracle database. What I have done is to set up several classpaths in DOS:
SET classpath=C:\ora_program\sqlj\lib\translator.zip;
SET classpath=C:\ora_program\sqlj\lib\runtime.zip;
SET classpath=C:\ora_program\sqlj\lib\runtime12.zip;
SET classpath=C:\ora_program\jdbc\lib\classes12.zip;
The code of my program is:
import java.sql.Date;
import java.sql.SQLException;
import oracle.sqlj.runtime.Oracle;
import java.util.Date;
public class Hello{
public static void main(String[] args){
java.sql.Date current_date;
try{
// connect to the db
Oracle.connect(
"C:\ora_program\bin",
"system",
"manager");
// get the current date from the database
#sql{SELECT sysdate INTO :current_date FROM dual};
// display message
System.out.println("Hello, the current date is: "+ current_date);
catch(SQLException e){
System.err.println("sqlException: "+e);
finally{
try{
Oracle.close();
catch(SQLException e){
System.err.println("sqlException: "+e);
And then I compile my program in DOS with the typing: sqlj Hello.sqlj
The program cannot be compiled and the error message is:
"Exception in thread main java.lang.NoClassDefFoundError: sqlj/tools/Sqlj"
It indicates that the SQLJ translator class files cannot be found.
I have set up the classpath in DOS (see above). How does the error come? Please help. Thanks.
PC>
SET classpath=C:\ora_program\sqlj\lib\translator.zip;
SET classpath=C:\ora_program\sqlj\lib\runtime.zip;
SET classpath=C:\ora_program\sqlj\lib\runtime12.zip;
SET classpath=C:\ora_program\jdbc\lib\classes12.zip;
The above only sets the classpath to the last value. You need to use the following.
SET classpath=%classpath%;C:\ora_program\sqlj\lib\runtime.zip; -
Exception in thread "main" java.lang.NoSuchMethodError?
This is the exact same error I recieved from running ListGames:
Exception in thread "main" java.lang.NoSuchMethodError: ListGames.getConnection(Ljava/lang/String;)Ljava/sql/Connection;
at ListGames.getGames(ListGames.java:21)
at ListGames.main(ListGames.java:7)
What's wrong?
ListGames.java:
import java.sql.*;
import java.text.NumberFormat;
import ...util.MysqlConnection; // purposely incomplete
public class ListGames {
static Connection conn = MysqlConnection.openMysqlConnection("ds_games");
public static void main(String args[]) {
NumberFormat cf = NumberFormat.getCurrencyInstance();
ResultSet games = getGames();
try {
while (games.next()) {
Game g = getGame(games);
String msg = Integer.toString(g.year) + ": " + g.title + " (" + cf.format(g.price) + ")";
System.out.println(msg);
} catch (SQLException e) {
e.printStackTrace();
conn = MysqlConnection.closeMysqlConnection(conn);
private static ResultSet getGames() {
try {
Statement s = conn.createStatement();
ResultSet rows = s.executeQuery("select title, year, price from my_ds_games order by year, price, title");
return rows;
} catch (SQLException e) {
e.printStackTrace();
conn = MysqlConnection.closeMysqlConnection(conn);
return null;
private static Game getGame(ResultSet games) {
try {
String title = games.getString("Title");
int year = games.getInt("Year");
double price = games.getDouble("Price");
return new Game(title, year, price);
} catch (SQLException e) {
e.printStackTrace();
conn = MysqlConnection.closeMysqlConnection(conn);
return null;
private static class Game {
public String title;
public int year;
public double price;
public Game(String title, int year, double price) {
this.title = title;
this.year = year;
this.price = price;
MysqlConnection.java:
package ...util; // purposely incomplete
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public final class MysqlConnection {
public static final Connection openMysqlConnection(String database) {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + database, user, password); // username and password purposely uninitialized
} catch(SQLException e) {
System.out.println("SQLException: " + e.getMessage());
System.out.println("SQLState: " + e.getSQLState());
System.out.println("VendorError: " + e.getErrorCode());
} catch(Exception e) {
e.printStackTrace();
} finally {
return conn;
public static final Connection closeMysqlConnection(Connection conn) {
try {
if (conn != null) {
conn.close();
if (conn == null) {
System.out.println("Conection Closed");
} catch (SQLException e) {
e.printStackTrace();
} finally {
return null;
}Darkstar444 wrote:
I deleted ListGames.class, ListGames$Games.class, and MysqlConnection.class but still the same thing.Then you didn't delete the version of ListGames.class which is actually being used when you run your application. This suggests that your classpath is pointing to an old version as well as to the version produced currently by the compiler. Or that there's an old version which you put into the Java extensions directory. -
Exception in thread "main" java.lang.NoClassDefFoundError: Emp/class
Dear all,
It occur 'Exception in thread "main" java.lang.NoClassDefFoundError: Emp/class' error when I test a oracle java sample.I've already SET CLASSPATH=C:\ORACLE\JDBC\LIB\CLASSE~1.ZIP.
following is the source code:
import java.sql.*;
class Emp
public static void main (String args [])
throws SQLException
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as <host>:<port>:<sid>. The example uses the short cut syntax.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@localhost:1521:orcl",
"scott", "tiger");
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP");
// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
Can you tell me what should also be set in classpath?
thanks in advance.You are right, the program is absolutely correct and I've run it before.but why set PATH=%PATH%;C:\ORACLE\JDBC\LIB\CLASSE~1.ZIP?I don't think it is correct.
I've ever run this jdbc program before and remeber only set classpath(path is also be set only for run executable program, for example set path=%path%;c:\j2sdk\bin),
I think the only difference with before is:
1,oracle version is changed from enterprise version to personal version
2,OS is changed from NT to windows 98
but i dont know if it lead to problem and can you give me some advice? -
Exception in thread "main" java.lang.NoClassDefFoundError: connect (wrong n
Please Help, I am giving up...
My PATH: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;c:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Java\jdk1.6.0_11\bin;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\JAVA DOCUMENTATION\BasicJava1\Code;C:\Program Files\Mysql Connector J\mysql-connector-java-5.1.7\mysql-connector-java-5.1.7-bin.jar
MY CLASSPATH: C:\Program Files\Mysql Connector J\mysql-connector-java-5.1.7\;C:\Program Files\Mysql Connector J\mysql-connector-java-5.1.7-bin
Before I set the ABOVE Path's I received the "com.mysql.jdbc.Driver" error. After adding the CLASS PATH as above I got the following Error
"com.mysql.jdbc.Driver"
After the ABOVE mentione PATH's Iam getting the following error:
C:\JAVA DOCUMENTATION>java connect
Exception in thread "main" java.lang.NoClassDefFoundError: connect (wrong name:
Connect)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: connect. Program will exit.
THIS IS MY CODE.....
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Connect
public static void main (String[] args)
Connection conn = null;
try
String userName = "sampadm";
String password = "secret";
String url = "jdbc:mysql://localhost/sampdb";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
catch (Exception e)
System.err.println ("Cannot connect to database server");
System.err.println("Exception: " + e.getMessage());
finally
if (conn != null)
try
conn.close ();
System.out.println ("Database connection terminated");
catch (Exception e) { /* ignore close errors */ }
PLEASE PLEASE HELP, AS I NEED TO GET PASSED THIS ERROR NOW. I NEED TO PROGRESS !!
THANKS TO ANYBODY THAT CAN ASSIST
FYI
JUDYJava is case sensitive. Connect != connect
-
Exception in thread "main" java.lang.NoClassDefFoundError: base
this is my error, in my progam there is a database which has to insert the values. but is not inserting.
the error is,
Exception in thread "main" java.lang.NoClassDefFoundError: base
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
and the code for that program is as follows
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.io.*;
class base
PreparedStatement pstmt=null;
Connection con = null;
Statement stmt = null;
ResultSet rset = null;
int est_effort;
String proj_id,proj_name,client_name,strt_date,est_date,proj_mgr;
void add( )
try
String driverName = "com.mysql.jdbc.Driver";
Class.forName(driverName);
String serverName = "192.168.10.253";
String mydatabase = "Trainees";
String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url
String username = "josep";
String password = "josep";
con = DriverManager.getConnection(url, username, password);
System.out.println("Connected");
catch(Exception e)
System.err.println("Exception: " + e.getMessage());
try{
pstmt = con.prepareStatement("INSERT INTO project(proj_id,proj_name,client_name,strt_date,est_date,proj_mgr,est_effort)VALUES
pstmt.setString (1,proj_id);
pstmt.setString (2,proj_name);
pstmt.setString (3,client_name);
pstmt.setString (4,strt_date);
pstmt.setString (5,est_date);
pstmt.setString(6,proj_mgr);
pstmt.setInt (7,est_effort);
pstmt.executeUpdate();
catch(Exception e)
System.err.println("Exception: " + e.getMessage());
finally
try
if(con != null)
con.close();
catch(SQLException e)
void modify()
void delete()
void assign()
class xx extends base
public static void main(String args[]) throws IOException
base a= new base();
a.add();
}If you are trying something like:java xxThen class xx should be public. (Also Base and Xx are better names for
classes.) -
I have the following configuration:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
on a Suse 10.1 Linux.
The javaversion is Java.Version = 1.4.2_11
The classpath does look like:
Eisele@brezn:~/FH-Weihenstephan/Winter_Semester_200809/Uebungen> echo $CLASSPATH
/derby.jar:/derbytools.jar:/derbynet.jar:/derbyclient.jar:/derbyTesting.jar:/local/derby/tools/java/jakarta-oro-2.0.8.jar:/derbyLocale_de_DE.jar:/derbyLocale_es.jar:/derbyLocale_fr.jar:/derbyLocale_it.jar:/derbyLocale_ja_JP.jar:/derbyLocale_ko_KR.jar:/derbyLocale_pt_BR.jar:/derbyLocale_zh_CN.jar:/derbyLocale_zh_TW.jar:/oracle/oracle/product/10.2.0/db_1/jdbc/lib/classes12.jar:/oracle/oracle/product/10.2.0/db_1/jdbc/lib/classes12.zip:/oracle/oracle/product/10.2.0/db_1/jlib/orai18n.jar:/oracle/oracle/product/10.2.0/db_1/jdbc/lib/ojdbc14.jar:/home/Eisele/Oracle/ojdbc14.jar:/home/Eisele/FH-Weihenstephan/Winter_Semester_200809/Uebungen
Eisele@brezn:~/FH-Weihenstephan/Winter_Semester_200809/Uebungen>
The Program JDBCVersion.java which I copied out of the Oracle-Documentation looks like:
import java.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;
class JDBCVersion
public static void main (String args[]) throws SQLException
System.out.println("Java.Version = " + System.getProperty("java.version")) ;
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:scott/tiger@host:port:service");
Connection conn = ods.getConnection();
// Create Oracle DatabaseMetaData object
DatabaseMetaData meta = conn.getMetaData();
// gets driver info:
System.out.println("JDBC driver version is " + meta.getDriverVersion());
I get the following error
Eisele@brezn:~/FH-Weihenstephan/Winter_Semester_200809/Uebungen> javac JDBCVersion.java
Eisele@brezn:~/FH-Weihenstephan/Winter_Semester_200809/Uebungen> java -cp ~/FH-Weihenstephan/Winter_Semester_200809/Uebungen/ JDBCVersion
Java.Version = 1.4.2_11
Exception in thread "main" java.lang.NoClassDefFoundError: oracle/jdbc/pool/OracleDataSource
at JDBCVersion.main(JDBCVersion.java:10)
Eisele@brezn:~/FH-Weihenstephan/Winter_Semester_200809/Uebungen>
Can anyone help me out here and tell me, what I did wrong ?
Thanks in advance !
RüdigerTwo thoughts.
The first is that 10.2.0.1 is unpatched. Why? It has been two years since its release and no one has applied 10.2.0.2, 10.2.0.3 or 10.2.0.4.
The second is that your question is not a database question but a Java question is you are more likely to get an answer that will help you if you post in a group where it is on-topic. -
Error complie "Exception in thread "main" java.lang.NoClassDefFoundError"
Dear All,
I have the following problem can not compile the code below.
Here my settings and the code.
Thanks for the help.
My java version.
===============================================
D:\bea\jdk150_22\bin>java -version
java version "1.5.0_22"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)
Java HotSpot(TM) Client VM (build 1.5.0_22-b03, mixed mode)
===============================================
I use a bat to compile the code
===============================================
set JDK_HOME=D:\bea\jdk150_22
set PATH=%JDK_HOME%\bin;%PATH%
set CLASSPATH=%CLASSPATH%;D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.jar
rem ---- compile
javac GetDBOracle.java
rem ---- testing
java GetDBOracle
rem ---- add to jar
jar cf GetDBOracle.jar GetDBOracle.class
===============================================
My java code
===============================================
import java.sql.*;
import java.io.*;
public class GetDBOracle {
public static String GetDBOracle(String Parm1, String Parm2) throws SQLException
String myResult = "";
// Load Oracle driver
DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
// Connect to the local database
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@localhost:ORCL", "ORC", "ORC2010");
// Query the employee names
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("SELECT JAVA_GET_VALUE('"Parm1"','"Parm2"') FROM DUAL");
// Print the name out
while (rset.next ()) {
myResult = rset.getString (1);
//close the result set, statement, and the connection
rset.close();
stmt.close();
conn.close();
return myResult;
public static void main(String args[])
try {
System.out.println(GetDBOracle("XXI", "12000"));
} catch (Exception e) {
System.out.println(e.getMessage());
===============================================
Erro
===============================================
Exception in thread "main" java.lang.NoClassDefFoundError: GetDBOracle
===============================================What happened to this Error complie "Exception in thread "main" java.lang.NoClassDefFoundError" ?
Maybe you are looking for
-
Mac mini - iMac-display via thunderbolt?
Is there any way to connect my mac mini to an iMac 21,5"-display with just a thunderbolt-cable between them? Both late 2011.
-
Hi All, I'm new to this site, but love blackberry phones. I need some help though. I'm looking into getting a Blackberry curve 8900 in the UK. Will this phone work in the USA? Thank you Mark Solved! Go to Solution.
-
Connecting iBook to television - scan rates
This may well be a stupid question, but it's late at night and my brain is already asleep! I want to connect my iBook G4 to a television to display some multimedia presentations, so I've bought the Apple Video Adapter. I also intend to get an s-video
-
La connection wifi fonctionne mal Wifi connection fails
The wifi connection does not work (after working perfectly). I cannot read or send mails and go to the internet. But it works fine with an ethernet cable. Yesterday, I reinstall Yosemite. It allows me to restore a good wifi connection. But after on
-
Whenever Apple's check for updates runs I get the message that a new version of Bonjour (1.0.5) is available. I install but it next time I get the same message. Anyone any idea what is happening?