Aravindan GP
asked on
Import oracle cannot be resolved
Hi,
My java code :
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.jdbc.OracleDriver;
public class ClassNameDemo {
public ClassNameDemo() {
System.out.println("Hello" );
System.setProperty("oracle .net.tns_a dmin","D:\ \TNSNAMES. ORA");
System.out.println("Hello" );
}
public void doit () throws SQLException {
System.out.println("H");
String usr = "MURUGANANTHAMM_CGZ_D2";
String pwd = "MURUGANANTHAMM_CGZ_D2";
System.out.println("He");
//String url = "jdbc:oracle:thin:@//134.6 5.171.119: 1521/sirdx 2";
String url = "jdbc:oracle:thin:@sirdx2" ;
System.out.println("Hel");
DriverManager.registerDriv er(new OracleDriver());
System.out.println("Hel1") ;
Connection conn = DriverManager.getConnectio n(url,usr, pwd);
System.out.println("Hell") ;
String sql = "select sysdate from dual" ;
System.out.println("Hello" );
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next())
System.out.println("result s: " + rs.getString(1));
conn.close();
}
public static void main(String[] args){
ClassNameDemo test = new ClassNameDemo();
try {
test.doit();
System.out.println("Done.. ");
}
catch (SQLException e) {
e.printStackTrace();
}
}
}
output :
Hello
Hello
H
He
Hel
Hel1
java.sql.SQLException: Io exception: SO Exception was generated
at oracle.jdbc.driver.Databas eError.thr owSqlExcep tion(Datab aseError.j ava:125)
at oracle.jdbc.driver.Databas eError.thr owSqlExcep tion(Datab aseError.j ava:162)
at oracle.jdbc.driver.Databas eError.thr owSqlExcep tion(Datab aseError.j ava:274)
at oracle.jdbc.driver.T4CConn ection.log on(T4CConn ection.jav a:319)
at oracle.jdbc.driver.Physica lConnectio n.<init>(P hysicalCon nection.ja va:344)
at oracle.jdbc.driver.T4CConn ection.<in it>(T4CCon nection.ja va:148)
at oracle.jdbc.driver.T4CDriv erExtensio n.getConne ction(T4CD riverExten sion.java: 32)
at oracle.jdbc.driver.OracleD river.conn ect(Oracle Driver.jav a:545)
at java.sql.DriverManager.get Connection (DriverMan ager.java: 539)
at java.sql.DriverManager.get Connection (DriverMan ager.java: 189)
at ClassNameDemo.doit(ClassNa meDemo.jav a:26)
at ClassNameDemo.main(ClassNa meDemo.jav a:40)
Please help with this error!
My java code :
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.jdbc.OracleDriver;
public class ClassNameDemo {
public ClassNameDemo() {
System.out.println("Hello"
System.setProperty("oracle
System.out.println("Hello"
}
public void doit () throws SQLException {
System.out.println("H");
String usr = "MURUGANANTHAMM_CGZ_D2";
String pwd = "MURUGANANTHAMM_CGZ_D2";
System.out.println("He");
//String url = "jdbc:oracle:thin:@//134.6
String url = "jdbc:oracle:thin:@sirdx2"
System.out.println("Hel");
DriverManager.registerDriv
System.out.println("Hel1")
Connection conn = DriverManager.getConnectio
System.out.println("Hell")
String sql = "select sysdate from dual" ;
System.out.println("Hello"
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next())
System.out.println("result
conn.close();
}
public static void main(String[] args){
ClassNameDemo test = new ClassNameDemo();
try {
test.doit();
System.out.println("Done..
}
catch (SQLException e) {
e.printStackTrace();
}
}
}
output :
Hello
Hello
H
He
Hel
Hel1
java.sql.SQLException: Io exception: SO Exception was generated
at oracle.jdbc.driver.Databas
at oracle.jdbc.driver.Databas
at oracle.jdbc.driver.Databas
at oracle.jdbc.driver.T4CConn
at oracle.jdbc.driver.Physica
at oracle.jdbc.driver.T4CConn
at oracle.jdbc.driver.T4CDriv
at oracle.jdbc.driver.OracleD
at java.sql.DriverManager.get
at java.sql.DriverManager.get
at ClassNameDemo.doit(ClassNa
at ClassNameDemo.main(ClassNa
Please help with this error!
Discard my first question.But I think you need hist ad port in the URL, and you commented out the correct URL and left the url without host and port part
I understand that getCinnection method is giveing excepotiion because of it
I understand that getCinnection method is giveing excepotiion because of it
This is the correct format of the URL for Orcale:
String URL = "jdbc:oracle:thin:@hostnam e.com:1521 :dbname";
String URL = "jdbc:oracle:thin:@hostnam
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
If it is, what is exactly line 125 ?