Home » Open Source » Programming Interfaces » JDBC Connection problem on Windows 2008 R2
JDBC Connection problem on Windows 2008 R2 [message #548022] Mon, 19 March 2012 11:33 Go to next message
sokol.ramaj
Messages: 1
Registered: March 2012
Junior Member
Hi ,

i'm having problems to connect to any DB (Oracle/ SQLServer) with java 7 from windows server 2008 R2.
below is my test code which when im running from my PC it's connecting but if i run it on the server it throws an exception.

i even tried to stop the firewall and again the same thing happens.
tnsping and sqlldr works fine only connection through jdbc fails.

do anyone have any idea for this issue??



Exception in thread "main" java.sql.SQLException: ☻
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
...
...


public class OracleDS {

    /**
     * @param args the command line arguments
     */
    public static void oracleConnection() throws SQLException {
        OracleDataSource ods = new OracleDataSource();
        ods.setTNSEntryName("orclTest");
        ods.setDriverType("oci8");

        ods.setUser("myUser");
        ods.setPassword("myPass");

        Connection conn = ods.getConnection();

        System.out.println("Oracle Connected");
    }

    public static void sqlServerConnection() throws SQLException {
        SQLServerDataSource ss = new SQLServerDataSource();


        ss.setServerName("myServer");
        ss.setDatabaseName("testDB");


        ss.setUser("myUser");
        ss.setPassword("myPass");

        Connection conn = ss.getConnection();

        System.out.println("SqlServer Connected");
    }

    public static void main(String[] args) throws SQLException {
        sqlServerConnection();
        oracleConnection();
    }
}

Re: JDBC Connection problem on Windows 2008 R2 [message #548024 is a reply to message #548022] Mon, 19 March 2012 12:24 Go to previous messageGo to next message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
This an Oracle forum.
You should post your question in a Microsoft forum.

Regards
Michel
Re: JDBC Connection problem on Windows 2008 R2 [message #548026 is a reply to message #548024] Mon, 19 March 2012 12:48 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
bcm@bcm-laptop:~$ cat Conn.java
import java.sql.*;
class Conn {
  public static void main (String[] args) throws Exception
  {
   Class.forName ("oracle.jdbc.OracleDriver");

   Connection conn = DriverManager.getConnection
     ("jdbc:oracle:thin:@//localhost:1521/v112", "scott", "tiger");
                        // @//machineName:port/SID,   userid,  password
   try {
     Statement stmt = conn.createStatement();
     try {
       ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
       try {
         while (rset.next())
           System.out.println (rset.getString(1));   // Print col 1
       } 
       finally {
          try { rset.close(); } catch (Exception ignore) {}
       }
     } 
     finally {
       try { stmt.close(); } catch (Exception ignore) {}
     }
   } 
   finally {
     try { conn.close(); } catch (Exception ignore) {}
   }
  }
}
bcm@bcm-laptop:~$ javac Conn.java
bcm@bcm-laptop:~$ export CLASSPATH=/u01/app/oracle/product/11.2.0/dbhome_1/owb/wf/lib/ojdbc14.jar:.
bcm@bcm-laptop:~$ java Conn
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE	11.2.0.1.0	Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
bcm@bcm-laptop:~$
Previous Topic: Need help VERY BADLY
Next Topic: Reg sending mail with attachment with perl script
Goto Forum:
  


Current Time: Thu Mar 28 17:09:09 CDT 2024