Solved

Run time or compiled

Posted on 1998-11-12
8
171 Views
Last Modified: 2013-11-23
Hi
I downloaded a trial vresion of VCafedb from Symantec.
What I noticed is that compiling a console Java application with this one created an .exe file. This exe file is capable of being started without using the java <file_name> procedure.All you do is you call the exe_file name like in any compiled application. Trying to run the same program using java <file_name> let's it run but do not make a connection to the database, while running the .exe file compiled with Symanted does do the connection. I suspect that using the JDK java <file_name> procedure does not access some libraries at runtime , necesary for the connection to the data base.
Can you please help ?
0
Comment
Question by:simi
  • 5
  • 3
8 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 1227311
you haven't posted enough information for us to help you:
so please write what error do you receive (and where exactly) with a piece of code

0
 

Author Comment

by:simi
ID: 1227312
Well what I did is I used SymantecdB to compile a console application that creates a frame , creates a connection to a database using dbAnywhere server and to display the result of an sql statement. It works. The Symanteddb compiler has created an .exe file that can also be run on its own. After the trial period for the Symantec compiler has expired I was still able to run the .exe file and it works.
Then I tried to use the JDK that I downloaded from the sun site to compile another little program that involved a connection to the data base and what happened was that the program compiled but when ran, using java <file_name> command, it did everithing but did not connect to the data base and no error message was displayed.
Then I tried to compile using the JDK, the same program I have compiled using the Symantecdb and the thing repeated. The program compiled but when ran it did everything but connecting to the database.
Even if I do not compile it with the JDK and I just run it using java <andd the file compiled with the Symantecdb(the .class file)>, it is the same situation, it runs but it does not connect.
As I said I suspect that at the run time the JDK does not find a path to some classes needed for the connection.

Thanks


0
 

Author Comment

by:simi
ID: 1227313
Well what I did is I used SymantecdB to compile a console application that creates a frame , creates a connection to a database using dbAnywhere server and to display the result of an sql statement. It works. The Symanteddb compiler has created an .exe file that can also be run on its own. After the trial period for the Symantec compiler has expired I was still able to run the .exe file and it works.
Then I tried to use the JDK that I downloaded from the sun site to compile another little program that involved a connection to the data base and what happened was that the program compiled but when ran, using java <file_name> command, it did everithing but did not connect to the data base and no error message was displayed.
Then I tried to compile using the JDK, the same program I have compiled using the Symantecdb and the thing repeated. The program compiled but when ran it did everything but connecting to the database.
Even if I do not compile it with the JDK and I just run it using java <andd the file compiled with the Symantecdb(the .class file)>, it is the same situation, it runs but it does not connect.
As I said I suspect that at the run time the JDK does not find a path to some classes needed for the connection.

Thanks


0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1227314
it's very strange that you receive no error messages
both javac (at compile time) and java (at run-time) will report errors if they can't file some class definitions that they need ... (for example ClassNotFoundException )

so maybe your second example works fine, but is does not tris to connect to the database ....
or check for some exception catching code (maybe you have received some exception but you have caught it in the code ?)
another one - SymantecDB uses its own java classes for connecting with its own dbAnehere server ...)

the best I can recoment is to take all the .java files from your first project (that produced .exe) to copy them in another directory and to compile them with Sun's JDK javac. if you success, try to run the main file (again with SUN's JDK)
any errors you receive may help us to solve the problem (and if it really does not work you should receive some errors ...)

hope this helps
 heyhey

0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 16

Expert Comment

by:heyhey_
ID: 1227315
and you can check if you have all the symantec classes included in the classpath (they probably use their own DB classes not standard JDBC), but again if java can't find any classes it needs it should issue warning message


0
 

Author Comment

by:simi
ID: 1227316
import java.awt.*;
import java.util.*;
import java.sql.*;

public class ConnectionExample extends Frame

{

      public ConnectionExample ()
      {
          super();
          this.show();
          this.resize(300, 300);
          TextArea textArea = new TextArea(25, 80);
          this.add("Center", textArea);



          try{
              String driverName = "symantec.itools.db.jdbc.Driver";
              Driver driver = (Driver)Class.forName(driverName).newInstance();
              Properties p = new Properties();
              p.put("user", "dba");
              p.put("password", "sql");
              String dbURL = "jdbc:dbaw://localhost:8889/Sybase_SQLANY/ASA 6.0 Sample/ASA 6.0 Sample";
              Connection connection = driver.connect(dbURL, p);
              Statement sqlStatement = connection.createStatement();
              String sql = "select emp_fname, emp_lname from employee";
              ResultSet results = sqlStatement.executeQuery(sql);
              String text = "";
              while(results.next())
              {
                  text += results.getString(1) + " " +
                         results.getString(2) + "\n";
              }
              textArea.setText(text);

          }
          catch(SQLException e){}
          catch(Exception e){}




            //{{INIT_CONTROLS
            /*setLayout(new BorderLayout(0,0));
            setVisible(false);
            setSize(104,0);*/
            //}}
                  //{{INIT_MENUS
            //}}
}

    static public void main(String args[]) {
        System.out.println("Hello World");
        ConnectionExample app = new ConnectionExample();
    }

            //{{DECLARE_CONTROLS
      //}}
      //{{DECLARE_MENUS
      //}}
}

This is the code.
First of all what I do not understand is why the Visual SymantecDB has created an .exe file.
My understanding was that every machine that wants to run java applications has to have installed an interpreter called JVM, that reads the bytecode generated by the java compiler and put.s it in the native machine code for that particular machine.
What happens with this .exe file ?
Second, and regarding the code above, if I  compile the code using javac it compiles OK. What I had to do was to add to the autoexec.bat file the CLASSPATH=C:\WHATEVER PATH\class.zip
I understand that this let's the compiler know where the JDBC classes are.
The documentation for the dbANYWHERE server, mentions that one should provide in his/her autoexec.bat file( or sc.ini file if he/she uses the VCafe from Symantec), the path to a file called dbaw.zip. I suspect that this file has something to do with the driver, as the driver mentioned in the URL is jdbc:dbaw etc.
They also provide four versions of this dbaw.file, in a resource directory, and they say that the user is supposed to pick the right one , according to the version of Symantec VCafe  that it uses. Well, they reffer to this as Symantec 1.0 2 that has JDK 1.1 etc.
I understand that the symantec compiler uses a version of the JDK.
Well I tried and renamed every provided file as dbaw.zip, one by one, and it did not work.
The behavoiur is that the frame get's created and that's it. Nothing happens and the dbANYWHERE server does not report any connection.
I am increasing the points to 100 as I think I underestimated the effort for answering to my question.

Thank you.



0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1227317
just a quick comment - you are possibly receiveng errors when ruuning the .class version, but your code ignores them - see

           catch(SQLException e){}
           catch(Exception e){}

I'll read your message later and check the code...
 heyhey
0
 
LVL 16

Accepted Solution

by:
heyhey_ earned 100 total points
ID: 1227318
so the answer
1.) it seems thay Symantec use standard jdbc, using their own native Driver "symantec.itools.db.jdbc.Driver"
2.) you can compile everything with JDK - that means that this is not a compile-time problem,
but look at this code
       String driverName = "symantec.itools.db.jdbc.Driver";
       Driver driver = (Driver)Class.forName(driverName).newInstance();
Class.forName(driverName) attempts to create a new class based on the name. this class is used only at run time - when you compile the program everything's ok, but when you run the program, you'll need (at least) one more file - that is the DBAnywhere JDBC driver named "symantec.itools.db.jdbc.Driver"
you should correct the problem by adding the .zip which contains this class file to your CLASSPATH, before starting the application
3.) why don't you receive any errors ?
look at the code
          catch(SQLException e){}
          catch(Exception e){}
so what ? you are catching all the possible errors without even indicating that something's worng !!!
the Good practice is to use
   catch (Exception e )
    {
        System.out.println("Error caught");
        e.printStackTrace();
    }

so you will see not only an error message, but also the stack trace (and you'll see the exact line number where the Exception was Created).
in your program you'll probably have "ClassNotFoundException" at this line
    Driver driver = (Driver)Class.forName(driverName).newInstance();
4.) about .class and .exe
Java was created as platform independend language, that;s wahy all Java programs are compiled to a universal (platform independend) format - .class. every user that has JVM implementation can start those programs.  But Java is just a languge - and you can create compiler for every language for every hardware platform. So there are some implementations of compilers that compile .java files to native code (for Win paltform - .exe and .dll) these are supposed to work much quicker than same program running from interpreting .class files ...

so that's all
got the points ? :)
  heyhey


0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
json format text only 4 65
mapAB Challlenge 35 89
solarwind tftp server 2 32
Java and GPO 11 47
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now