Jdbc in applets

I get the applet panel displayed in a web page. however when the user clicks on the button contained within the panel, nothing happens. In the appletviewer clicking on the button leads to a applet window containing data retrieved from the database (which is required)???

there is lots of stuff on this site about applet signing. It seems complicated at first but its not that bad. In fact, if you had looked first, you would see there is a signed applet forum (!)
anyway, signing the applet is all very well but the crux of it is that applets connecting straight into databases is not good design. If you are just learning, however, then you might try it out but you probably won't (or at least shouldn't) be asked to do it on a job.
maybe if u used a servlet for JDBC, and the applet could connect to that?

Similar Messages

  • Use of jdbc in applets

    hi ,
    i am priya i am a learner of java and i am facing some of the problems in using jdbc with applets
    i am using ms-access as database and it shows some error messages when i compile the code such as
    access denied due to applet security etc
    So, please help me in this way so that i can use applets with jdbc
    thanx,

    I second that. Using JFrame instead of JApplet is easy once you've seen an example:
    http://java.sun.com/docs/books/tutorial/uiswing/learn/example1.html
    When learning Swing, I can think of only disadvantages to using JApplet over
    JFrame. Why do textbooks use applets? Old habits die hard and they
    are out-of-date in their view of Java.
    Side comment: when learning a new topic, like JDBC, I would
    strongly advice you to write the simplest possible code at first.
    In other words, skip the Swing and write simple console apps:
    1. select and dump the contents of a table.
    2. gradually do more sophisticated selects...
    3. insert a record into a table using some fixed values.
    3. delete records from a table.
    4. update records using some fixed values.
    Once you are comfortable doing CRUD, and used PreparedStatement!,
    then add a GUI. And if your code is well-written, the GUI and the back-end
    are separate enough anyway, that you can write and test them apart.

  • JDBC through Applet...

    We are getting 'AccessControlException' while using JDBC through Applet.
    Can anybody suggest the changes to be made in the policy file OR security setting OR security Manager.

    The tutorial gives help about it at :
    http://java.sun.com/docs/books/tutorial/security1.2/tour1/index.html
    hope it will help.

  • JDBC in applet URGENT

    Hi,
    I have created an application by using JDBC,now i would like to convert this application into applet and put it online. So i register a domain name, create a jar file for this application and use browser to load it. But so far from what i know, online features have to be done by using JSP,so is it possible to use JDBC to connect to database and do functions online?If not,it means i have to replace JDBC by JSP?
    Thanks for any help.

    Hi
    Please make note of some points:
    1. You can very well create your application as an Applet and then connect to a database through JDBC.
    2. If you think you can make use of the server resources properly you can go ahead with your applet. Otherwise you can switch to JSP, but you may not get any useful resources like Swing, JFC and other stuff through plain jsp, for all these you need an applet as a container for these.
    The problems you are facing is because applets are not secure, you need to sign your applet so as to make use of the system resources available and the applet to interact with your client machines. when you create your jar file you have to sign it using the jarsigner bound to a security certificate installed. Through java you can create your own self signed certificate with the keytool option available in your jdk. Then you have to use the HTMLConverter and pass the HTML file containing the applet tags pointing to your class file, this will convert the applet into browser readable format. Then you are all set, open the applet through your browser and <b>BINGO</b> you are up and moving.
    If you have any more doubts please feel free to ask me.
    Thanks
    Swaraj

  • Problem with Using JDBC in Applet

    Hi,
    i have written an applet to log in (it checks the database, if the username and pasword exists it shows corresponding message). i use access or sql server and applet is started but no message is shown(i think it does not connect to database). here is my code:
    import javax.swing.*;
    import java.sql.*;
    import java.awt.event.*;
    import java.awt.*;
    public class appletDatabase extends JApplet implements ActionListener {
    JLabel l1;
    JLabel l2;
    JLabel l3;
    JTextField tf1;
    JPasswordField tf2;
    JButton btn;
    Connection cn;
    Statement st;
    String hostname;
    public void init() {
    hostname = "localhost";
    l1 = new JLabel("User Name: ");
    l2 = new JLabel(" Password: ");
    l3 = new JLabel(" ");
    tf1 = new JTextField(20);
    tf2 = new JPasswordField(20);
    btn = new JButton("Sign in");
    Container c = getContentPane();
    c.setLayout(new FlowLayout(FlowLayout.LEFT));
    c.add(l1);
    c.add(tf1);
    c.add(l2);
    c.add(tf2);
    c.add(btn);
    c.add(l3);
    btn.addActionListener(this);
    setSize(300,300);
    setVisible(true);
    public void actionPerformed(ActionEvent e) {
    if (e.getSource()==btn) {
    boolean b = check(tf1.getText(),new String(tf2.getPassword()));
    if (b) {
    l3.setForeground(Color.green);
    l3.setText("Username and password exists. ");
    else {
    l3.setForeground(Color.red);
    l3.setText("Username and/or password does not exist.");
    public boolean check(String un, String pass) {
    String query="SELECT * FROM Table1 WHERE username LIKE'"+un+"'" +
    " AND password LIKE'"+pass+"'";
    boolean b = false;
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    cn = DriverManager.getConnection("jdbc:odbc:login");
    st = cn.createStatement();
    ResultSet rs = st.executeQuery(query);
    if (!(rs==null))
    if (rs.next())
    b = true;
    rs.close();
    st.close();
    cn.close();
    } catch (SQLException e1) {
    e1.printStackTrace();
    } catch (ClassNotFoundException e1) {
    e1.printStackTrace();
    return b;
    }

    The first thing i notice is that there's a problem with your SQL statement.
    To start with you should probably be using PreparedStatements cause it deals with the passing of variables very well and cleanly.
    But if you must use a straight statement then it should be like this:
    String query = "SELECT * FROM Table1 WHERE username LIKE '"+un+"'" + " AND password LIKE '"+pass+"'";
    The fact that you were mising a few spaces wouldn't have helped. Although if you were to use a prepared statement, it would be a lot easier to understand where things were being passed and you don't need to worry about those single quotes for certain values.
    Wes

  • Cann't access oracle 9i with thin jdbc and applet

    Hi..
    I write thin jdbc applet and application programs..
    application programs works well..
    but applet cann't connect...
    error messages below..
    access denied (java.util.PropertyPermission oracle.jserver.version read)
    web server and dbms server are on same machine...
    applet programs is in the demo applet program of oracle's installation folders...
    I hope your comment...
    thanks..

    Hi Hyun,
    This is basically just a guess -- since you didn't provide a lot of information (in my opinion) -- but I assume that "oracle.jserver.version" is some "System" property.
    Due to the security restrictions placed on an applet (and which aren't imposed on an application), an applet cannot access all of the "System" properties -- only some of them (like "java.version", for example). So that's why (I think) your application works, but your applet doesn't.
    There are several workarounds for overcoming an applet's security restrictions -- the most popular (as far as I know) is to "sign" your applet. There are many Internet resources available that explain how to "sign" an applet -- a simple Internet search will be more than enough to get you going (if that's at all relevant to your situation).
    Hope this has helped you.
    Good Luck,
    Avi.

  • Jdbc and applet

    I have Jdbc code which is running fine as a stand alone program. When i integrated it with an apllet it gives me
    access denied (java.lang.RuntimePermission accessClassInPackage.sun.jdbc.odbc)
    I m using netbeans. 3.6 The intersting thing is the code runs when I debug it But gives the above error when i execute it. I hope some one can help me out. It is urgent

    You should urgently read this:
    http://java.sun.com/docs/books/tutorial/applet/overview/security.html

  • SQL Server 2000 - JDBC + Java Applet problem

    Hai
    I have some problem connecting my SQL server database with Java.
    I use Applet to make my interface.
    I use Windows 2000 server.
    Here is my program listing :
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.sql.*;
    public class VLookup extends JApplet {
    String database = "jdbc:odbc:Driver={SQL Server};SERVER=Windows2000;uid=sa;pwd=;Database=User-Phone Database";
    String user = "sa";
    String password = "";
    Statement s;
    Connection c;
    JTextField searchFor = new JTextField(10);
    JLabel completion = new JLabel(" ");
    JTextArea results = new JTextArea(40, 20);
    public void init() {
    searchFor.getDocument().addDocumentListener(new SearchL());
    JPanel p = new JPanel();
    p.add(new Label("ID to search for :"));
    p.add(searchFor);
    p.add(completion);
    Container cp = getContentPane();
    cp.setLayout(new BorderLayout());
    cp.add(p, BorderLayout.NORTH);
    cp.add(results, BorderLayout.CENTER);
    try {
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
    c = DriverManager.getConnection(database, user, password);
    s = c.createStatement();
    } catch(Exception e) {
    results.setText(e.getMessage());
    class SearchL implements DocumentListener {
    public void changedUpdate(DocumentEvent e){}
    public void insertUpdate(DocumentEvent e){
    textValueChanged();
    public void removeUpdate(DocumentEvent e){
    textValueChanged();
    public void textValueChanged() {
    ResultSet r;
    if(searchFor.getText().length() == 0) {
    completion.setText("");
    results.setText("");
    return;
    try {
    r = s.executeQuery("SELECT " + "Tipe " + "FROM " + "Time " + "WHERE " + "(Tipe Like '" + searchFor.getText() + "%') "
    + "GROUP BY " + "Tipe " + "ORDER BY " + "Tipe " );
    if(r.next())
    completion.setText(r.getString("Tipe"));
    r = s.executeQuery("SELECT " + "ID_Pengguna, Phone_Number, Tipe " + "FROM " + "Time "
    + "WHERE " + "(Tipe ='" + completion.getText() + "') "
    + "GROUP BY " + "ID_Pengguna, Phone_Number, Tipe "
    + "ORDER BY " + "ID_Pengguna, Phone_Number " );
    } catch(Exception e) {
    results.setText(searchFor.getText() + "\n");
    results.append(e.getMessage());
    return;
    results.setText("");
    try {
    while(r.next()) {
    results.append(r.getString("ID_Pengguna") + ", " + r.getString("Phone_Number") + ", " + r.getString("Tipe") + "\n");
    } catch(Exception e) {
    results.setText(e.getMessage());
    public static void main(String[] args) {
    JApplet applet = new VLookup();
    JFrame frame = new JFrame("User ID");
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e){
    System.exit(0);
    frame.add(applet);
    frame.setSize(500, 200);
    applet.init();
    applet.start();
    frame.setVisible(true);
    } ///:~
    And java catch error like this : access denied (java.lang.RuntimePermission access ClassInPackage.sun.jdbc.odbc)
    What is wrong ??
    Is there any problem with my DNS ? 'cos I don't know how to set up my DNS.
    Can u help my with this problem ??
    Thank's

    You need to read up on what applets are capable of. Applets generally cannot open connections to things like databases due to sandboxing. There are a couple of ways to get around this. The applet can connect to a servlet on the same machine from which it came and have the servlet do the database accesses. Alternately, you can create a signed applet which allows you to get around some of these sandboxing issues.If tried to make localhost on my computer ( by setting my IIS configuration setting, and using Configure SQL XML Support in IIS I've created a new http://localhost/skripsi to my SQL database.
    Is there any command that I have to add to my program listing so the applet can work as I wish ??
    Is there any way to use applet to connect my database withaout using servlet, and can u explain siggned applet to mey ??
    Sorry, I don't really know java very well.
    driver type 4 ??

  • JDBC and Applets

    I'm trying to view results of a query in an applet.
    Keep getting the error
    ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
    I know there is security issues. can i get around them???
    This application runs perfect in a driver program...
    can anyone help??????
    Thanks

    I set the policy tool but it still returning "ClassNotFoundException"
    Could you check my code to see if there is anything wrong???
         String url = "jdbc:odbc:timetable";
         String query = "select Day, Room from Thirdyear";
         try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
         } catch(Exception ex) {
         text.appendText("My Error: \n" + ex);
    text.appendText("\n" + ex);
    System.out.println(ex);
         // return;
         try {
         Connection con = DriverManager.getConnection(url, "", "");
         Statement stmt = con.createStatement();
         ResultSet rs = stmt.executeQuery(query);

  • JDBC with Applet

    Hi All,
    My program uses Applet with JDBC. Everything in the program seems to be fine, but the error displayed does not give me a clue of where i'm going wrong. This is the error...
    java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
         at java.net.URLClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClassInternal(Unknown Source)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at Applet1.connectToDB(Applet1.java:60)
         at Applet1.access$0(Applet1.java:56)
         at Applet1$1.actionPerformed(Applet1.java:44)
         at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
         at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at javax.swing.JComponent.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)
    and the func to establish the connectivity is as given here..
    private void connectToDB(ActionEvent e)
              try { // load the driver
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    } catch (Exception e1) { // problem loading driver, class not exist?
    e1.printStackTrace();
    return;
    try {
    //connection = DriverManager.getConnection();
    con = DriverManager.getConnection("jdbc:oracle:thin:@my.com","nit","nit");
    System.out.println("Connection successful!");
              empValues.setText("Connected to the Database.Fetching Values from DEPT Tables.\n");
    fetchValues();
    } catch (SQLException ex) {
    System.out.println("Connection Error = " + ex.toString());
    please let me know where i'm going wrong....
    thanks,
    ng

    The problem is not with the port number. The driver class is not found in your case. You need to have the driver class in the classpath. I am not sure how this is done for applets. You could check the applet tutorial for that.
    But, as I am thinking about the problem, if your applet is directly executing JDBC, you will need to include the driver jar with the applet. This will make the applet bulkier and slower to download since the applet is downloaded on the client side. What you should do is use a server-side component, a servlet prefereably, which will manage the database calls and communicate with the applet. This will eliminate the need for including the driver jar with the applet.

  • Policies, JDBC and applets

    I have looked all over the WWW for info on this and have found loads of questions but not one clear cut answer. It's amazing the number of "OK, thanks, I got it working" without saying how. Here is my problem. I have a JDBC applet, running on IE. If I run it locally it works like a champ. If I run it through "localhost:xxx.html I get that infamous "Unable to connect to MySQL on localhost:3306, are you sure it's running..Java.security.accesscontrol exception. One problem mentioned setting a policy..didn't mention which one though. So I set socket connection priv on localhost:3306 as that was explicitly mentioned in the exception. Seemed like a good idea. It was but still did not solve the problem. So what I think would be really swell is if in one place there was a really good answer on how to set up an applet using JDBC under IE to work with respect to the security manager. Could someone please help?
    Thanks in Advance,
    Walt

    Hi,
    Let's first c an example of the intended functions of the two methods.
    We have an HTML-type document, "document.html" at:
    host_name/some_directory/document.html
    and we have our applet, "OurApplet.class" at:
    host_name/some_directory/applets/OurApplet.class
    In the "document.html", we have embedded "OurApplet.class" inside. Then getDocumentBase().toString() should supposedly be:
    host_name/some_directory/document.html
    and getCodeBase().toString() should supposedly be:
    host_name/some_directory/applets/OurApplet.class
    If the directories containing the HTML document and the applet were the same, both methods would give the same thing; if they r not, it'd be like the above.
    Ok, the above is the way they'r intended to be. According to the bug ChuckBing has shown us (actually the methods r under the class java.applet.Applet instead of under the package java.applet), the two methods however produce what their counterpart friends is supposed to produce. So if your version of SDK/JRE produces the bugged version of the output, u can replace the method with its counterpart friend. However, keep in mind of the target JRE the applet will be run on and the possibility of more than one potential audience JREs.

  • JDBC Vs Applet

    Hi ,
    I have a problem in JSP that is I have to get some values from the table throug JDBC and I have to print that values on a Applet window. I think java applet window will not support for JDBC code. So How can I print all the values throgh Applet?
    With Regards
    Prakash.A

    The applet can make a socket connection or HttpUrlConnection back to the server it came from to request the data. You'll need a socket server or servlet on the server to do the SQL queru and return the data.

  • Database Connection (JDBC) by Applet

    Hi all,
    I create a database connection from applet ,it worked only compiler means Jbuilder.
    But just after I put it on tomcat It gave error .It didnt work there.It gives follwing error.
    access denied (java.lang.RuntimePermission accessClassInPackage.sun.jdbc.odbc)
    If any one knows the solution please help me.
    Thanks
    Virajchi

    Hi all,
    Dont worry about this question.
    I found the solution.
    Cant load directly Jdbc driver to the applet.
    That directly applet cant communicate with database.
    Cheers,
    Virajchi

  • JDBC and Applet communication

    HI!
    I am not able to connect my Oracle datbase in Applet.
    Please give ur suggestions.
    Thanx in Adv
    Vink

    Hi
    An applet can request a socket connection only to the server from which it is downloaded from.
    If your database and the webserver are running on different hosts then the applet security model restricts the applet from connecting to the database. You need to set the proper security policies and sign the applets.
    Refer the following link on applets
    http://developer.java.sun.com/developer/technicalArticles/Security/Signed/
    Also post the complete error/stack traces if you get into some problems.
    Hope this helps
    shrini

  • Jdbc in applet

    Hi,
    I have an applet which is connecting to a database , getting some info in order to show it but when I run it from Eclipse->Run->Run As->Java Applet everything is fine. When I put it in .html <applet> tag and try to view it through appletviewer I got ClassNotFoundException. Is it something with the classpath because I have put the directory the applet is situated in in the classpath environmental variable or the applet needs to be signed which I didn't got how is done.
    Please help and thanks in advance.

    The classpath for an applet is specified in the HTML from which the applet is loaded. Obviously the classpath system variable on the client's machine can't be used, because you can't tell users "You have to set your classpath before you can run my applet". And besides, you want to use jars that are on the server and not on the client.
    I think it's the archive attribute of the applet element in your HTML, but I can't remember and I don't really care because I don't write applets. I'm sure the applet tutorial explains that.

Maybe you are looking for