开发者

problem with jdbc when I use Jar file and command prompt

I use JDeveloper for develop a JDBC program, now my program finished and I want to run it separately I have problem when I try to run my jar file from command prompt.

my program cannot connect to my oracle database when I am using command prompt to run my program!But When I use my JDeveloper IDE there is no issue! my IDE run this command:

javaw.exe -client -classpath C:\JDeveloper\mywork\SourceManagmentTools\.adf;C:\JDeveloper\mywork\SourceManagmentTools\Client\classes;C:\Oracle\Middleware\jdeveloper\jdev\lib\jdev-rt.jar;C:\JDeveloper\mywork\SourceManagmentTools\Client\ojdbc14.jar;C:\JDeveloper\mywork\SourceManagmentTools\Client\quaqua-filechooser-only.jar;C:\JDeveloper\mywork\SourceManagmentTools\Client\quaqua-test.jar;C:\JDeveloper\mywork\SourceManagmentTools\Client\quaqua.jar;C:\JDeveloper\mywork\SourceManagmentTools\Client\swing-layout.jar;C:\JDeveloper\mywork\SourceManagmentTools\Client\image;C:\JDeveloper\mywork\SourceManagmentTools\Client\lipstikLF-1.1.jar -Djavax.net.ssl.trustStore=C:\Oracle\Middleware\wlserver_10.3\server\lib\DemoTrust.jks Main.GUI.SmRun amir

I use this command :

Java -jar smt.jar amir

when I run my IDE command there is no issue,every thing work fine, would you please help me? (my program running & working just I can not fetch data from database)

I receive below error when I try to select from my database...

C:\JDeveloper\mywork\SourceManagmentTools\Client\deploy>java -jar smt.jar amir
[Ljava.lang.StackTraceElement;@7a148bd3[Ljava.lang.StackTraceElement;@51b48197[L
java.lang.StackTraceElement;@58ecb281[Ljava.lang.StackTraceElement;@25fa1bb6[Lja
va.lang.StackTraceElement;@62da3a1e[Ljava.lang.StackTraceElement;@15f48262[Ljava
.lang.StackTraceElement;@7dc05ffd[Ljava.lang.StackTraceElement;@15e232b5[Ljava.l
ang.StackTraceElement;@36baa466[Ljava.lang.StackTraceElement;@177f409c[Ljava.lan
g.StackTraceElement;@2b8bbc5a[Ljava.lang.StackTraceElement;@62facf0b[Ljava.lang.
StackTraceElement;@5ff3ce5c[Ljava.lang.StackTraceElement;@561777b1Exception in t
hread "AWT-EventQueue-0" java.lang.NullPointerException
        at Main.Database.SmDatabase.selectCustomers(SmDatabase.java:151)
        at Main.GUI.SmCreateProject.this_windowOpened(SmCreateProject.java:109)
        at Main.GUI.SmCreateProject.access$000(SmCreateProject.java:30)
        at Main.GUI.SmCreateProject$1.windowOpened(SmCreateProject.java:58)
        at java.awt.AWTEventMulticaster.windowOpened(Unknown Source)
        at java.awt.Window.processWindowEvent(Unknown Source)
        at javax.swing.JDialog.processWindowEvent(Unknown Source)
   开发者_C百科     at java.awt.Window.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

part of mydatabase class:

public class SmDatabase {

    Connection conn = null;

    public SmDatabase() {
        try {
            String drivername = "oracle.jdbc.driver.OracleDriver";
            Class.forName(drivername);

            String ServerName = "127.0.0.1";
            String ProtNumber = "1521";
            //String sid = "DEVP0";
            String sid = "cms";

            String url =
                "jdbc:oracle:thin:@" + ServerName + ":" + ProtNumber + ":" +
                sid;

            //String Username = "PENTAVCB";
            //String Password = "pentasoft123";
            String Username = "cmsuser";
            String Password = "pass";

            conn = DriverManager.getConnection(url, Username, Password);
        } catch (ClassNotFoundException e) {
            System.out.print(e.getStackTrace());
        } catch (SQLException se) {
            System.out.print(se.getStackTrace());
        }
    }

public Vector<String[]> selectCustomers(String command) {
    ResultSet resultSet = null;
    Statement statement;
    Vector<String[]> customerName = new Vector<String[]>();
    try {
        statement = conn.createStatement();
LINE151     resultSet = statement.executeQuery(command);

        while (resultSet.next()) {
            String[] temp = new String[2];
            temp[0] = resultSet.getString("V_CUST_NAME");
            temp[1] = resultSet.getString("V_CUST_CODE");
            customerName.add(temp);
        }
        resultSet.close();
        statement.close();
        //    conn.close();
    } catch (SQLException e) {
        System.out.println(e.getStackTrace());
    }
    return customerName;
}


e.printStackTrace(); will produce far more useful output than System.out.println(e.getStackTrace());. I would change that everywhere it appears in your application and try again. DriverManager.getConnection(url, Username, Password); is most likely throwing an exception that you're not printing properly, which produces the "[Ljava.lang.StackTraceElement..." garbage.


The output indicates a null pointer exception at line 151 which should indicate that the "statement" variable is null. The "conn" is not null or the exception would have been thrown at the previous line. This is strange, if you have a valid connection tyou should be able to get a Statement. Is it possible the line number is off by 1? Can you change your code to:


   if conn is null  System.out.println("conn is null!!!");
   else System.out.println("conn is set");

   statement = conn.createStatement();   

   if statement is null  System.out.println("statement is null!!!");
   else System.out.println("statement is set");

   resultSet = statement.executeQuery(command);

   if resultSet is null  System.out.println("resultSet is null!!!");
   else System.out.println("resultSet is set");

I don't see where SmDatabase is called to set conn. Is it called from somewhere else? Does the call catch the exception and not print an error message?


What exception are you getting? If it's a ClassNotFoundException, then you just need to add -cp oracleclient.jar to the command.

The Oracle client jar can also be put at the end of the -classpath arguement passed to java.exe.


I solve my problem by using this command:

java -client -classpath ojdbc14.jar;lipstikLF-1.1.jar;swing-layout.jar;smt.jar Main.GUI.SmRun rimrim

I guess those library we used in our project need also run, but I am not sure, I just suggest this work

java -client -classpath <name of you library>;<name of you library>;<name of your jar file> nameOfPackage.nameOfRunClass parameter[if any]

I will so appreciate if anybody add some useful info to this post

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜