Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 21st, 2002, 12:49 PM
Keiichi Keiichi is offline
aHVoPw==
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2001
Posts: 1,058 Keiichi User rank is Lance Corporal (50 - 100 Reputation Level)Keiichi User rank is Lance Corporal (50 - 100 Reputation Level)Keiichi User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 15 h 24 m 31 sec
Reputation Power: 9
Using applets and mysql (w/php)

I want to be able to create an applet and be able to use it to access data from mysql.

I tried doing searches in this forum and the best thing I found was from this thread:
http://forums.devshed.com/showthread.php?threadid=44040
down at the post with the php coding by alexgreg

He says to "point" your Java applet to the php file. What does that mean? (how do you do that with code?) I do know some of Java, but not that great with file manipulation.
Also, what does that code do? I see that the php file prints data gathered from mysql. How would the applet accept this?

Thanks for any help.
__________________
K1

Reply With Quote
  #2  
Old December 22nd, 2002, 12:19 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
Well, applets run client side, so you cannot access mysql directly. What you can do is have your applet contact something that can, namely a php script.

What you have to do in your applet is use a URL object to open a connection to the php script. In effect, it is acting as its own little browser by opening another connection. This way you can send any info you want to the php script and have it access mysql, then return whatever info to the applet for display.

Hope that helps.

Reply With Quote
  #3  
Old December 22nd, 2002, 09:40 PM
Shocka's Avatar
Shocka Shocka is offline
dont click here
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 409 Shocka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 35 m
Reputation Power: 7
Connect to a MYSQL DB using JDBC, like any other Application/Servlet anything.

here is a simple Java Class, that shows how to conect to a MySQL DB. If you want to dl a file to test it. http://www.risrani.com/testr/mysqlJDBC.txt


or here is the code. You just have to change few things pretty self explanatory

Code:
import java.sql.*;

//Goto mysql.com and download the mm.mySQL Drivers.
//Unzip and copy mysql-connector-j-2.0.14-bin.jar to you CLASSPATH
//or into the same directory where all you .class files will lie.
//Here is a same code you should be able to figure it out.


public class Connector {
  public static void main(String args[]){
    try {
      Class.forName("com.mysql.jdbc.Driver");
      Connection con =
          DriverManager.getConnection(
          "jdbc:mysql://localhost/dbname", "user", "password");
      String query  = "Select * from TABLE";
      Statement s = con.createStatement();
      ResultSet rs = s.executeQuery(query);
      while(rs.next()){
        System.out.println(rs.getString(1));
      }
      con.close();
    }
    catch (Exception ex) {
      System.out.println(ex.getMessage());
    }
  }
}


perhaps u can extend this class to have a method to query or update the DB and such and simply call this class everything.

Last edited by Shocka : December 22nd, 2002 at 09:43 PM.

Reply With Quote
  #4  
Old December 22nd, 2002, 09:57 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Quote:
Unzip and copy mysql-connector-j-2.0.14-bin.jar to you CLASSPATH


Correct me if I'm wrong, but this has to be the *clients* classpath, right?
__________________
-james

Reply With Quote
  #5  
Old December 23rd, 2002, 12:22 AM
Shocka's Avatar
Shocka Shocka is offline
dont click here
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 409 Shocka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 35 m
Reputation Power: 7
good question.. i havnt tried this yet.. but i assume u can put it in the same path as the class file on the server. but i dont stand by that answer..


does anyone have an MySQL server i can use to test this out.. i actually want to find out the answer.

Reply With Quote
  #6  
Old December 23rd, 2002, 09:09 AM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
You are very correct that the Applet should be able to connect to mysql directly, as long as the mysql server and the web server (where the applet came from) are the same box (applets cannot connect to anything other than the server they originated from). However, the mysql driver jar would have to be downloaded to the client with the applet jar. You can do this by putting both jar files in the "archive" attribute of the applet/object tag.

Example:
Code:
<applet width="100" height="100" 
  code="mypackage.myclass"
  codebase="."
  archive="myApplet.jar, mysqlDriver.jar">
</applet>


Then your code *should* work. Unfortunately, the mysql driver is 435k, which is a rather large download for a modem user. Also, mysql has to be set up to allow non-localhost connections. If you do not have admin rights to mysql this may be a problem.

Reply With Quote
  #7  
Old December 23rd, 2002, 01:30 PM
Shocka's Avatar
Shocka Shocka is offline
dont click here
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 409 Shocka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 35 m
Reputation Power: 7
well i know for a fact you do not have to specify the driver in the archive list,

there is an example of an applet that connects to a Sybase DB on my schools site. But i am unable to figure out where they have put the Driver archive. And the HTML pointing to the point is pointing to 1 class no archives at all.


As for the mysql settting like nemi said if you have no admin power and u are set to localhost this wont work at all.

Reply With Quote
  #8  
Old December 23rd, 2002, 02:10 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Shocka, could the applet be using ODBC? I think the jdbc:odbc bridge comes with the JVM.

Reply With Quote
  #9  
Old December 23rd, 2002, 05:07 PM
Shocka's Avatar
Shocka Shocka is offline
dont click here
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 409 Shocka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 35 m
Reputation Power: 7
Quote:
Originally posted by bricker42
Shocka, could the applet be using ODBC? I think the jdbcdbc bridge comes with the JVM.


it might be... but at school they stress the use of the Sybase drivers to connect to the DB.. but they dont always practice what they preach

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Using applets and mysql (w/php)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway