powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / Java + Oracle EE 11g Connection errors
3 сообщений из 3, страница 1 из 1
Java + Oracle EE 11g Connection errors
    #38218253
Philip_Stubborn
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Всем, привет.
Написал на java приложение небольшое, в котором нужно подключение к oracle
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package orathinconnection;
import java.io.*;
import java.sql.*;
import java.util.Locale;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;
import oracle.jdbc.OracleConnection; 
import oracle.jdbc.OracleDriver; 

/**
 *
 * @author Admin
 */
public class OraThinConnection {

    /**
     * @param args the command line arguments
     */
    
    
    
    public Connection dbConnection()throws Exception
{

      //Connection con=null;
     // Locale.setDefault(Locale.ENGLISH);
      Class.forName("oracle.jdbc.driver.OracleDriver");
      
      return DriverManager.getConnection(      
          "jdbc:oracle:thin:@HOST_IP:1521:db",
        "user",
        "password"        
           );
//return DriverManager.getConnection(myDB,"","");
}
    
    
    
     public Vector getEmployee()throws Exception
     {
    
      Vector<Vector<String>> employeeVector = new Vector<Vector<String>>();
    
      Connection con = dbConnection();
      //Statement s=con.createStatement();
      PreparedStatement pre = con.prepareStatement("SELECT * from table");
     ResultSet rs =  pre.executeQuery();
     while (rs.next()) {        
         
Vector<String> employee = new Vector<String>();
employee.add(rs.getString(1)); //Empid
employee.add(rs.getString(2)); //name
employee.add(rs.getString(3)); //position
//employee.add(rs.getString(4)); //department
employeeVector.add(employee);

        
    //  s.close();
  
     } 
     if(con!=null)
con.close();

return employeeVector;
   // catch(Exception e){e.printStackTrace();}
 }
}




И класс, в котором я вызываю это соединение
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Table;
import java.util.Vector;
import orathinconnection.OraThinConnection;
/**
 *
 * @author Admin
 */
public class Table extends javax.swing.JFrame {

    /**
     * Creates new form Table
     */
    private Vector<Vector<String>> data; //used for data from database
    private Vector<String> header; //used to store data header
    
    public Table()throws Exception {
        
        //get data from database
        OraThinConnection orathinconnection = new OraThinConnection();
        data = orathinconnection.getEmployee();
        
        //create header for the table
        header = new Vector<String>();
        header.add("Surname"); //Empid
        header.add("Name"); // employee name
        header.add("Pat_Name"); // employee position
     //   header.add("Department"); // employee department
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(

        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 25, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 25, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Table.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Table.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Table.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Table.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
          //  @Override
            public void run() {
                try
                {
                new Table().setVisible(true);
                }
                catch(Exception e){e.printStackTrace();}
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration                   
}



Ошибка
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
java.sql.SQLRecoverableException: Ошибка ввода/вывода: The Network Adapter could not establish the connection
	at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:475)
	at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:552)
	at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:253)
	at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
	at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:526)
	at java.sql.DriverManager.getConnection(DriverManager.java:579)
	at java.sql.DriverManager.getConnection(DriverManager.java:221)
	at orathinconnection.OraThinConnection.dbConnection(OraThinConnection.java:35)
	at orathinconnection.OraThinConnection.getEmployee(OraThinConnection.java:58)
	at Table.Table.<init>(Table.java:24)
	at Table.Table$1.run(Table.java:105)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:711)
	at java.awt.EventQueue.access$000(EventQueue.java:104)
	at java.awt.EventQueue$3.run(EventQueue.java:672)
	at java.awt.EventQueue$3.run(EventQueue.java:670)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:681)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
	at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:439)
	at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:434)
	at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:687)
	at oracle.net.ns.NSProtocol.connect(NSProtocol.java:247)
	at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1126)
	at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:337)
	... 24 more
Caused by: java.net.ConnectException: Connection timed out: connect
	at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
	at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
	at java.net.Socket.connect(Socket.java:579)
	at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:149)
	at oracle.net.nt.ConnOption.connect(ConnOption.java:133)
	at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:405)
	... 29 more
...
Рейтинг: 0 / 0
Java + Oracle EE 11g Connection errors
    #38218275
Озверин
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Philip_Stubborn,

есть подозрение, что дело не в java

авторCaused by: java.net.ConnectException: Connection timed out: connect

Попингуйте хост из persistence.xml
...
Рейтинг: 0 / 0
Java + Oracle EE 11g Connection errors
    #38218303
Philip_Stubborn
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Озверин,
Спасибо. Да, дело было в том, что я HOST_IP не тот указал.
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / Java + Oracle EE 11g Connection errors
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]