Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Connect To Database From Within Java Applet

Posted on 2011-02-22
13
1,393 Views
Last Modified: 2012-06-27
Dear Experts,

Can I do connect to database (i.e. SQL Server,Oracle or SQL CE 4.0) from within Java Applet,?

if not, is there any ways to do communcation between applet and any database?

Thank you,
0
Comment
Question by:Bassam_Basamad
  • 8
  • 4
13 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 34949437
That's how you do it with thin JDBC driver:
   
try {


            Class.forName ("oracle.jdbc.driver.OracleDriver");
         conn =
                      DriverManager.getConnection ("jdbc:oracle:thin:@host_name:1521:SID",
             user, password);

        stmt = conn.createStatement();


 addressVector = new Vector();
  ResultSet rs0 = stmt.executeQuery("select email from  table_name");

 while (rs0.next()) {

  addressVector.addElement(new InternetAddress(rs0.getString("email")));

  }

conn.close();
  } catch(Exception ex) {....
}

Open in new window



0
 
LVL 47

Expert Comment

by:for_yan
ID: 34949442
Yes you can connect to the databse from Applet if the instance is running on the
same host as web server
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34949459
 Applet, even unsigned, allows network connections to the server from which it was loaded,
therefore if your database instance is running on the same server as the web server
from which you loaded applet, then you can connect to database - I did this way may times.

Signed applet can connect to other servers, but signing is rather painful operation,
and installing web server is usually rather simple, so you can isntall and setup web server
on the same server where you have database and in this way be able to access it from applet.
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

Author Comment

by:Bassam_Basamad
ID: 34949464
Normally the applet can be accessed from client browser so in the client browser there is no Oracle or SQL Server running, is it possiple to run this code inside the applet within client browser not on the server or web server.

Thank you
0
 
LVL 92

Assisted Solution

by:objects
objects earned 20 total points
ID: 34949465
the following explains how to self sign a jar http://helpdesk.objects.com.au/java/how-to-self-sign-a-jar
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34949496
No, of course you don't have database on the client machine, you can have web server (not to be mixed up with web browser) on the same machine
as Oracle database - your client will only have browser and applet will run in his browser, but it can
communicate wityh your server, where you have databse, and from which it could have been loaded if it also had web server.
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 105 total points
ID: 34949549
You actually can  have all your web pages loaded from another web server, you just need to set up most simple
web serevr on the same host as database only to host applet code there and nothing more  - and this would already allow you
to contact your databse directly from the applet. I use it all the time and folks in the company around here use
these applets and have no problems with it.
0
 

Author Comment

by:Bassam_Basamad
ID: 34949607
Could you please, post any working example to connect to SQL Server, SQL CE (Recommended) or Oralce  from within Applet,

Thank you,
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34949614
I posted the code above how to connect to Oracle - this code
is indpendent whether you need to connect from Java application or applet - all
connection details will be the same
0
 
LVL 47

Accepted Solution

by:
for_yan earned 105 total points
ID: 34949622
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34949630
The only thing that you'll have to have jdbc driver - and these drivers - they are pure java - jar files
will be different for Oracle and for SQL server - you want to decide which one you will be using
and then download them eiither from Oracle or from Microsoft
0
 

Author Comment

by:Bassam_Basamad
ID: 34950732
Thank you for helpful answers, actually what I need to do is connecting my applet to SQL CE database, to read some settings before it launch,That's why I have used the Web service to call from wihin applet, and that web service can connect to this SQL CE,and  return XML data as settings but I have faced a problem when I browse the page from remote pc not in the same local pc.

Can you help me, in this issue please,
I have post this question in another post, can you look at it,please?
http://www.experts-exchange.com/Programming/Languages/Java/J2EE/Q_26838137.html

Thank you
0
 

Author Closing Comment

by:Bassam_Basamad
ID: 34960002
Doesnot provide a way to SQL CE in java.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

839 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