Solved

java webstart + mysql

Posted on 2006-11-17
9
816 Views
Last Modified: 2008-01-09
Hi,
i've write a little class to connect to mysql server:
        Connection conn = null;
        try {
            String userName = "root";
            String password = "admin";
            String url = "jdbc:mysql://hostname:3306/cs";
            try {
                      Class.forName("com.mysql.jdbc.Driver").newInstance();
            } catch (Exception e) {
                System.err.println(e.toString());
            }
           try {
                conn = DriverManager.getConnection(url, userName, password);
                System.out.println("Database connection established");
            } catch (Exception e) {
                System.err.println(e.getStackTrace());
            }
        } catch (Exception e) {
            System.err.println(e.toString());

        }
If the class is executed in a Java application, it's ok, but when using Java Webstart i  get error shown below:

Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION
java.net.SocketException
MESSAGE: java.security.AccessControlException: access denied (java.net.SocketPermission hostname:3306 connect,resolve)
STACKTRACE:
java.net.SocketException: java.security.AccessControlException: access denied (java.net.SocketPermission hostname:3306 connect,resolve)tat com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
com.mysql.jdbc.Connection.createNewIO(Connection.java:2641)
com.mysql.jdbc.Connection.<init>(Connection.java:1531)
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
java.sql.DriverManager.getConnection(DriverManager.java:525)
java.sql.DriverManager.getConnection(DriverManager.java:171)
Cs.getNewConnection(Cs.java:218)
Cs.start(Cs.java:452)
Cs.<init>(Cs.java:1234)
Cs$21.run(Cs.java:1709)
java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
** END NESTED EXCEPTION **
packet sent to the server was 371 ms ago.

i test this class in NetBeans 5.0 ide environment, and the database is located in a remote server.
i try to add <security> <all-permissions/> </security> tag to my jnlp file bat an error message tell me that the jar is not signed (obviously,i did that)

..thank you

0
Comment
Question by:dany996
  • 4
  • 4
9 Comments
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 250 total points
ID: 17967727
you need to sign the application in order to connect
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 17968724
check that u have signed it correctly.
were u propmted to accept the certificate?
0
 

Author Comment

by:dany996
ID: 17972802
..sorry but this problem drive crazy.


i try to debug the class in the NetBeans 5.0 ide environment the problems are:
      (i should sign the jar also in debug mode?, if so, how can do it?)

      in debug i get this exception "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" when i try
      to execute Class.forName("com.mysql.jdbc.Driver").newInstance();

      so i've insert into the jnlp resources entry:
              <resources locale="" os="">
                <jar download="eager" href="dist/mysql-connector-java-5.0.3-bin.jar" main="false" version=""/>
              </resources>

      in this case the drive is loaded but when the statement below is executed  i get the
      java.security.AccessControlException: access denied (java.net.SocketPermission hostname:3306 connect,resolve)
      
            conn = DriverManager.getConnection(url, userName, password);
      
      

      so  i try to deploy the application and then sing then jar and the mysql-connector-java-5.0.3-bin.jar
      put the war file on the tomcat server, stop the service replace the jar with the signed one
      then restart.

      in this case i get the error

      An error has been taken place during  the execution of the application.

            Title: test
            Fornitore: Company, Inc.
            category: download error

            resource not signed: http://hostname:8080/prova/dist/mysql-connector-java-5.0.3-bin.jar
            
      ..but the jar is singed!

      this is the jnlp generated by netbeans:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jnlp PUBLIC "-//Sun Microsystems, Inc.//DTD JNLP 1.5//EN" "http://www.netbeans.org/jnlp/DTD/jnlp.dtd">
<jnlp codebase="$$codebase" href="prova.jnlp">
  <information>
    <title>test</title>
    <vendor>Company, Inc.</vendor>
    <homepage href="homepage.html"/>
    <description> </description>
    <icon href="default"/>
    <offline-allowed/>
    <shortcut online="true"/>
  </information>
  <resources>
    <j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/>
  </resources>
  <resources>
    <jar download="eager" href="dist/prova.jar" main="false"/>
  </resources>
  <resources locale="" os="">
    <jar download="eager" href="dist/mysql-connector-java-5.0.3-bin.jar" main="false" version=""/>
  </resources>
  <application-desc main-class="prova.Main"/>
</jnlp>


thanks
      

0
 
LVL 92

Expert Comment

by:objects
ID: 17973537
yes u need to include the mysql jar in your jnlp, and u also need to sign that jar
if its saying it isn't then  check it isn't being cached, and its using an unsigned version

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:dany996
ID: 17976372
i solved the problem, for unknown reason the java web start said the mysql-connector-java-5.0.3-bin.jar was unsigned
but the jarsign -verify confirmed me that jar was correctly signed!
so, i unziped the jar then i removed the manifest file, zip again and then sign again.
after this all works fine.

someone can explain me why?

0
 
LVL 92

Expert Comment

by:objects
ID: 17977430
was it signed with the same cert that you app was signed with?
0
 

Author Comment

by:dany996
ID: 17981645
..yes.
0
 

Author Comment

by:dany996
ID: 17981688
sorry, i'd like to share points to  Ajay-Singh and objects,
how can i do?
0
 
LVL 92

Expert Comment

by:objects
ID: 17983056
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
My project did see openJDK that I installed. What could be the problem 7 123
firstswap challenge 20 67
java  and programming certification ? 4 86
Java and GPO 11 70
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

911 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

23 Experts available now in Live!

Get 1:1 Help Now