my dog learned polymorphism*
The moose likes Servlets and the fly likes JavaApp -> Servlet -> mysqlDB? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JavaApp -> Servlet -> mysqlDB?" Watch "JavaApp -> Servlet -> mysqlDB?" New topic
Author

JavaApp -> Servlet -> mysqlDB?

Jeremee Mccann
Greenhorn

Joined: Nov 03, 2013
Posts: 9
Hello,

Hoping someone can set me straight on what exactly a Servlet is. I have a basic website i'm making for work, more of a hobby that anything else. I have log system setup with mysql and PHP utilizing XAMP for now. I have a calendar app in java that I was using jdbc:mysql to connect directly to the database. works perfectly. Then it occurred to me all my passwords are floating around in this jar.

So instead I tried java URLConnection posting to a PHP page and reading XMLechos. It will only work once then i get a premature end of file error.

So my question is..

Should I try and learn more about PHP, XML and URLConnection and get that to work or is there a better way?

Should I create another java program as a Servlet and use that?

How is a servlet anymore safe, can someone download my Servlet to get db connection info? (i understand they won't be downloading it to use the "calendar")

Please can someone outline the proper interaction to keep the database secure. Its not sensitive data anyway but i'd like to learn the correct way if i can help it

Thank you!

-Jeremee.

ps I have about a month of programming experience under my belt so be gentle!
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9915
    
158

Jeremee, can you post the relevant code from your servlet so that we can better understand the context of your question?

[My Blog] [JavaRanch Journal]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

No. Nobody can download your code and see the connection info.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeremee Mccann
Greenhorn

Joined: Nov 03, 2013
Posts: 9
Hi, thanks for the replys sorry I was so unclear. My old setup that worked was a jar file that had 3 classes one of the classes had my mysql connection info in it. this jar would be used as a "calendar" for the client but hosted on my server. Is my login info safe in that jar? Couldnt they access the source to get the connection info if it was hard coded in? IE not passed in as a variable. What is the best approach to fix that issue?

I decided I needed a servlet instead so that the servlet would contain connection info and it wouldnt ever be passed to the user, just accessed by the "calendar". The servlet currently isn't a java jar it is just a .php file that accepts posts from the calendar, runs a sql query and generates a xml file. The xml is read by the calendar applet. (works once, and only once.)

Can a php file act in the manner i'm attempting or do I need a java based class extending servlet?

I'll post any of the code as soon as I get home, i'm at work atm and can't get to it all. I really looking for a explanation of the process I need to implement, and the safely of my connection info. I don't mind googling how to do it all after I'm set on the right path. Thanks again!

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

Jeremee Mccann wrote:Is my login info safe in that jar?

Again, the Java code stays on the server.

Couldnt they access the source to get the connection info if it was hard coded in?

No. Not unless they can log into your server, in which case all bets are off. Are you giving them ssh access? No. So, no.
Jeremee Mccann
Greenhorn

Joined: Nov 03, 2013
Posts: 9
Thank you so much for clearing that up. Servlet seemed kind of overkill for a very simple website.

How would I pass the connection info in to the applet if I wanted to do so? That way when I move from testing and server I dont have to change it in the jar? I had it setup so it echoed out into the javascript that launched the applet but anyone could just view the page source to see the info. I keep hearing AJAX but i'm not sure... if so i'll look into that.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

Applets are there own deal and have little or nothing to do with servlets. Perhaps you should post a detailed question on the applet side of things in the Applets forum.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaApp -> Servlet -> mysqlDB?
 
Similar Threads
JSP/Servlet VS PHP
"porting" a PHP application to Java...
PHP Beginner needs help!
Eclipse for JEE & PHP?
Need career guidance...