无法使用JAVAFX和Oracle DB

时间:2015-12-03 08:09:57

标签: java oracle javafx

我正在使用java fx创建登录到oracle db的loginsystem。我在这里遇到了两个问题,1。我无法连接到DB 2.我不确定我是否将ojdbc jar放到正确的位置。

所以我的代码是, UTIL / ConnectionDB.java

package Util;

import java.sql.*;
/**
 * Created by engineering09 on 12/3/2015.
 */

public class ConnectionDB {

    private static final String DB_USER = "WELTESMIN";
    private static final String DB_PASS = "123pass";
    private static final String DB_NAME = "WEN";

    public boolean openConnection(){
        boolean result;

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection conn = null;

            conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:"+DB_NAME+"",DB_USER,DB_PASS);

            if (conn != null){
                System.out.println("CONNECTION DONE");
            }
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
            result = false;
        }

        return result;
    }
}

和主要,

package Controller;

import Util.ConnectionDB;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("../View/login.fxml"));
        primaryStage.setTitle("Weltes Oxygen Management");
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
        testConnection();
    }

    public void testConnection(){
        ConnectionDB connect = new ConnectionDB();
        connect.openConnection();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Project Sctructure

请帮帮我,这是我的错误消息

  

java.sql.SQLRecoverableException:IO错误:网络适配器可以   没有建立连接   oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:489)at   oracle.jdbc.driver.PhysicalConnection。(PhysicalConnection.java:553)     在oracle.jdbc.driver.T4CConnection。(T4CConnection.java:254)     在   oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)     在oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528)at   java.sql.DriverManager.getConnection(DriverManager.java:664)at   java.sql.DriverManager.getConnection(DriverManager.java:247)at   Util.ConnectionDB.openConnection(ConnectionDB.java:30)at   Controller.Main.testConnection(Main.java:23)at   Controller.Main.start(Main.java:18)at   com.sun.javafx.application.LauncherImpl.lambda $ launchApplication1 $ 163(LauncherImpl.java:863)     在   com.sun.javafx.application.PlatformImpl.lambda $ runAndWait $ 176(PlatformImpl.java:326)     在   com.sun.javafx.application.PlatformImpl.lambda为$ null $ 174(PlatformImpl.java:295)     在java.security.AccessController.doPrivileged(Native Method)at   com.sun.javafx.application.PlatformImpl.lambda $ runLater $ 175(PlatformImpl.java:294)     在   com.sun.glass.ui.InvokeLaterDispatcher $ Future.run(InvokeLaterDispatcher.java:95)     at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)at   com.sun.glass.ui.win.WinApplication.lambda为$ null $ 149(WinApplication.java:191)     在java.lang.Thread.run(Thread.java:745)引起:   oracle.net.ns.NetException:网络适配器无法建立   连接在   oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:439)at   oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:454)     at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:693)     在oracle.net.ns.NSProtocol.connect(NSProtocol.java:251)at   oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1140)at at   oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:340)... 18   更多引起:java.net.ConnectException:连接被拒绝:连接     at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)     在   java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)     在   java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)     在   java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)     在   java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)     在java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)at   java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)at   java.net.Socket.connect(Socket.java:589)at   oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:149)at at   oracle.net.nt.ConnOption.connect(ConnOption.java:133)at   oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:405)

0 个答案:

没有答案