Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

Run time or compiled

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
simi
Asked:
simi
  • 5
  • 3
1 Solution
 
heyhey_Commented:
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
 
simiAuthor Commented:
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
 
simiAuthor Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
heyhey_Commented:
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
 
heyhey_Commented:
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
 
simiAuthor Commented:
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
 
heyhey_Commented:
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
 
heyhey_Commented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now