Define mysql and host connection only 1 place

Hi everyone,
For my school project i developed a application using servlets and jsp.
In every servlet i make a new connection.
Like this:
public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        System.out.println("MySQL Connect Example.");
        Connection conn = null;
        String url = "jdbc:mysql://127.0.0.1:3306/";
        String dbName = "cijfersysteem";
        String userName = "vishant";
        String password = "vishant";
        String driver = "com.mysql.jdbc.Driver";But if my host changes for example i need to change it in 10 or more files.
that is not efficient.
How can i make the connection in 1 file and require it over every other servlet?
Thnx in advance for the help everyone.

If you are using Tomcat or Jetty, you can define JNDI entries like this:
[http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#JDBC%20Data%20Sources]
[http://docs.codehaus.org/display/JETTY/JNDI]
You should be using resource injection in Glassfish.

Similar Messages

  • How do I turn off my internet connection via 3G and be connected only to Wifi and vise vera? Iphone 4s

    How do I turn off my internet connection via 3G and be connected only to Wifi and vise vera? Iphone 4s

    Kappy wrote:
    The menubar for the Finder and your Desktop along with the date, time, and Spotlight icons. Looks like this:
    If it isn't present then open Network preferences, select the Airport port, check the box labeled: "Show Wi-Fi status in menubar." You can also turn Airport off in this same place.
    This is the iPhone forums

  • Performance with MySQL and Database connectivity toolbox

    Hi!
    I'm having quite some problems with the performance of MySQL and Database connectivity toolbox. However, I'm very happy with the ease of using database connectivity toolbox. The background is:
    I have 61 variables (ints and floats) which I would like to save in the MySQL-database. This is no problem, however, the loop time increases from 8ms to 50ms when using the database. I have concluded that it has to do with the DB Tools Insert Data.vi and I think that I have some kind of performance issue with this VI. The CPU never reach more the 15% of its maximum performance. I use a default setup and connect through ODBC.
    My questions are:
    1. I would like to save 61 variables each 8-10ms, is this impossible using this solution?
    2. Is there any way of increasing the performance of the DB Tools Insert Data.vi or use any other VI?
    3. Is there any way of adjusting the MySQL setup to achieve better performance?
    Thank you very much for your time.
    Regards,
    Mattias

    First of all, thank you very much for your time. All of you have been really good support to me.
    >> Is your database on a different computer?  Does your loop execute 61 times? 
    Database is on the same computer as the MySQL server.
    The loop saves 61 values at once to the database, in one SQL-statement.
    I have now added the front panel and block diagram for my test-VI. I have implemented the queue system and separate loops for producer and consumer. However, since the queue is building up faster then the consumer loop consumes values, the queue is building up quite fast and the disc starts working.
    The test database table that I add data to is created by a simple:
    create table test(aa int, bb char(15));
    ...I'm sure that this can be improved in some way.
    I always open and close the connection to the database "outside the loop". However, it still takes some 40-50 ms to save the data to the database table - so, unfortunatly no progress to far. I currently just want to save the data.
    Any more advise will be gratefully accepted.
    Regards,
    Mattias
    Message Edited by mattias@hv on 10-23-2007 07:50 AM
    Attachments:
    front panel 2.JPG ‏101 KB
    block diagram.JPG ‏135 KB

  • Suddenly my ethernet and firewall are no longer connected. router is good...and can connect only using wifi...suggestions?

    suddenly my ethernet and firewall are no longer connected. router is good...and can connect only using wifi...suggestions?

    SOLUTION! 
    I've been suffering from this problem for a few months.  I tried everything suggested by everyone, and then, today, I had a mad idea. 
    I used to work in a room in the house that's about 12 metres away from the router. It's on the next storey up and horizontally about 8 metres away.  The problem started when I began to work in the same room as the router. 
    Today I became so frustrated that for some reason I walked into a room about 8 metres away on the same level - Guess what?  I connected with no problem at all. Feeling full of joy I walked back to the room where the router is located - Dropped internet connection within a few minutes!  Walked back to the the room that's 8 metres away and, hey presto! I have a connection. I now realise that the problem was that I moved too close to the router.
    I can think of no logical explanation for my experience, but empirically it seems to work.  Does anyone have the faintest idea of why this should be the case?  In the absence of an answer I think I may have to start believing in fairies at the bottom of the garden - I'm just off to set a meal for them.
    By the way, I don't know if it has any significance, but the router is a BT Infinity router that has replaced the incredibly unreliable Virgin Media cable connection

  • FMS3 and FCS Connectivity Issue

    When FCS and FMS3 connection takes place, i get following
    error in FCS's Machine regarding the FCS crash.
    "Macromedia Flash Comminication Server MX 1.7.1 r98 has
    encountered a problem and needs to close. We are sorry for the
    inconvenience.
    Error signature
    szAppName : FlashCom.exe szAppVer : 1.7.1.98 szModName :
    js32.dll szModVer : 0.0.0.0 offset : 000033c1"

    This is just a guess as I'm not a Transall user. My first guess is that your DSN will need to be made using the 32-bit ODBC driver. As a default, using Windows 7 or later, you created a 64-bit source.
    To create or modify a 32-bit DSN on 64-bit Windows, you must run C:\WINDOWS\SysWOW64\odbcad32.exe. You may find it useful to create a shortcut to this on your desktop or Start menu if you access it frequently. I believe the interface is exactly the same after that.

  • I can't get my website to connect to mysql database hosted on my yahoo site

    I used David Powers tutorials to build a CMS website in Dreamweaver using a testing site set up on my computer. I installed XAMPP and got it working on my computer. (I have a Windows 7 PC with Dreamweaver CS6)
    Now I have installed the mysql database on my remote site following the instructions in the help section of Yahoo Small Business, where my website is hosted. I recreated the same database on the myPHPAdmin on my remote site. (If I understood what I found out when searching for a solution, Yahoo doesn't allow me to see the database from Dreamweaver. It seems that I have to make sure the connections are correct and then upload my site to the remote server. Then it should work once up)
    Following the instructions I could find on Yahoo it seems that all I needed to do was make sure that the user name and password were the same as on my local computer and change the my Sql Server in the Server Connection in Dreamweaver CS6 to mysql instead of localhost, upload my website and it should connect. When I go to my webpage online I get "No database selected".
    I know html, css, some php, and mysql.
    I have been using Dreamweaver for approximatley 2 years and have created 2 successful websites for my husband, who is a photographer. He now wants to have a blog type news website and since I couldn't get Wordpress to do what he wanted to do I decided to create a CMS website. It works great on my computer, but now I need it to work on my remote site.
    I know it's probably something really stupid that I have overlooked and I would really appreciate any help I could get.
    I'm more than happy to learn whatever I need to learn to get this done. I have been searching all kinds of forums and I can find a lot of posts about this or a similar problem, but no solutions.
    Please let me know if I need to provide more information.

    I'm sorry, the way I wrote that was confusing. In mysql it suggested you create a new user that had limited access to access each database you created, rather than use the root user which had all permissions. So in both the mysql on my computer and the mysql on my website I created a user with the same username and password, so that when my website was on my remote server the username and password were the same as when I was testing it on my local computer.
    SnakEyez02 wrote:
    Following the instructions I could find on Yahoo it seems that all I needed to do was make sure that the user name and password were the same as on my local computer and change the my Sql Server in the Server Connection in Dreamweaver CS6 to mysql instead of localhost, upload my website and it should connect. When I go to my webpage online I get "No database selected".
    Just looking at that part of your response, I don't get what they are asking you.  Typically the remote host will require that you update the username/password and possibly SQL server.  When you are in most shared environments, which is what I presume you are in, you typically have a username that is prefix_username.  So you should be updating your script to match that information, not the other way around.  Also with the "mysql instead of localhost" comment, you would only change the script from localhost to another server (ip address) if the mySQL server is not on your web server.  If you host tells you this is true thent he value should be an IP address instead of localhost.  Is that the case?
    For the second part of your question in the "Why can't I access my database" help on Yahoo it says "If your PHP or Perl configuration files require a host name, you may have a problem with your host name. Make sure that you are using the host name mysql, not the default host name localhost." I assumed that meant that in the setup menu when establishing a server connection I needed to replace "localhost" as the mysql Server with "mysql" and then upload my website. This didn't work. Since the mysql server I am trying to access can be accessed using phpmyadmin at www.mywebsite.com/phpmyadmin this seemed to make sense to me. I think I might have managed to access the mysql server, but I'm not choosing the database I want correctly.

  • I upgraded from Dreamweaver CS4 to CS6. but now "an TFP error occured - cannot make connection to host". I spent hours with the host technician and we cant find the error. I reinstalled DW4 and it connects to host perfectly. Anyone else seen this problem?

    I upgraded from Dreamweaver CS4 to CS6. but now when I want to upload I get "an TFP error occured - cannot make connection to host". I spent hours with the host technician and we cant find the error. I reinstalled DW4 and it connects to host perfectly. Anyone else seen this problem?
    Mac OS 10.8.5
    None of these issues are causing the error in DW CS6. We have double checked all of them and we have everything exactly right. Also I have exactly the same SiteSetup in DW CS4 and that works perfectly well. Could there must be factor in 6 that didn't exist in 4? Something that isnt in the SiteSetup but in some hidden dialog box ?
    I can also upload to my host using Fetch, a third party FTP. And as I said DW CS4 works fine. So the problem is not with my host, its with DW CS6 in particular.

    Thank you Jon, that fixed it perfectly. You have saved me from going crazy. The only difference I see now is in "Server Name" it changed what I had entered (my ftp address) to "Remote Server"; which seems odd -- but it works!   Although I know there maybe also some other dialog box I have never seen
    Of course I saw that menu item "Import"  and but I thought thats obviously not for me: "Why would I want to import an entire website?". I did not however see "Export the selected site" for thats only a tiny icon in the footer. However I would have thought the same:  "Why would I want to export my entire website?".
    An observation: I've seen this problem in a lot of Adobe software, the menu-names of items are  obscure, non descriptive. What would be better would be for the menu names or popups to say "Export Site Setup settings" and "Import Site Setup settings"

  • Connecting a Local Java Program with a Mysql Database Hosted on the Interne

    I need help. I want to connect a java program running on local user computers to read and write to a mysql database hosted in my domain by an internet service provider.
    What code do i use?
    How do i connect?

    http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/JDBC20.html
    You'll ned to downloda the JDBC driver file from MySQL, and check their docs for the format of the connection URL.

  • HT1338 When I connect my Macbook Pro to my Dell DLP projector, either via cable or wirelessly, I just see a dark screen with the mouse and mouse trails only, can any one help?

    When I connect my Macbook Pro to my Dell DLP projector, either via cable or wirelessly, I just see a dark screen with the mouse and mouse trails only, can any one help?

    jpmarkques post is a good start point, after folling his directions, you can try detect displays. Also try different rsolution and refresh rates.
    Most of the projectors I have used support a 1024X768 res.
    Youcan also try a pram reset if it still does not detect.
    Leave theproctor connected and powered up, power down the MBP.
    Power back up the MBP and hold the following keys before you hear the start up chime:
    Option, command, P,R (no commas) continue to hold these keys till you hear the start up chime 2 times.

  • My iphone 4S only start whit cable plug in and then show battery very low (with red line end) then try to turn on but show searching in operator name command and not connecting and no work properly and when I plug out it turn off!!! what should I do?

    My iphone 4S only start whit cable plug in and then show battery very low (with red line end) then try to turn on but show searching in operator name command and not connecting and no work properly and when I plug out it turn off!!! what should I do?

    I'm afraid you'll have to get the phone serviced, dropping the phone must have damaged additional parts inside the phone.
    But Apple will not service the phone anymore, opening the phone and replacing the battery should only be done by authorized personal, not by users.
    You'll have to look for a 3rd party repair shop and see if they can fix this, sorry.

  • I have a video that I created for my daughter's first birthday.  The hard drive on my computer crashed and I lost the video file.  The only place I have it is on my iPod Classic.  How can I transfer the video from my iPod to my new hard drive?

    I have a video that I created for my daughter's first birthday.  The hard drive on my computer crashed and I lost the video file.  The only place I have it is on my iPod Classic.  How can I transfer the video from my iPod to my new hard drive?

    You are in luck, Refer to this recent post by tt2, on recovering media using 3rd Party Software.
    He has made a comprehensive list, browse through them and decide which  suits your requirements.
    Have a nice day!

  • Can't connect to the internet in my home yet other devices can. I tried it in other Wifi places and it connects without a problem. My home Wifi is with Att uverse

    Can't connect to the internet in my home yet other devices can. I tried it in other wifi places and it connects without a problem. My home wifi is with ATT Uverse. I cheched the IP address on my laptop and its different than on my Ipod although it on the same network.

    Move off WEP to WPA or, preferably, to WPA2 (as recommended by Apple). WEP has been deprecated by the WiFi Alliance since 2004 as insecure (it can be cracked in seconds by any hacker).
    Note that each device on a network has a unique IP address but if your address starts with 169 then you did not get a valid IP address assigned to you by your router. If restarting the router did not cure the problem then you should check for a firmware update for your router.

  • HT4279 I have a Macbook Pro (late 2012) and I would like to connect it to 2 screens simultaneously (1 screen is a TV and can only take HDMI, the other is a larger computer screen and has both VGA and HDMI connections). How can I do this?

    I have a Macbook Pro (late 2012) and I would like to connect it to 2 screens simultaneously (1 screen is a TV and can only take HDMI, the other is a larger computer screen and has both VGA and HDMI connections). How can I do this?

    The article you cited refers to The Mac Pro, a 50lb silver tower -- not a notebook computer.
    Everymac.com says:
    2nd Display Support:
    Dual/Mirroring*
    2nd Max. Resolution:
    2560x1600 (x2*)
    Details:
    *This model supports a simultaneous maximum resolution up to 2560x1600 on two external displays via Thunderbolt. Alternately, it can support a single display up to 2560x1600 via Thunderbolt and a single display up to 1920x1200 via HDMI. Although it can theoretically power all three external displays, as confirmed by a helpful reader, it runs too hot with three displays connected.
    Also see: How many external displays can the Retina Display MacBook Pro models support? What is the maximum supported resolution of each? Are adapters required?
    When using other than ThunderBolt displays, the ThunderBolt port is directly compatible with Mini DisplayPort, and can be forced into compatibility (with Single-Link DVI or HDMI up to 1920 wide) with a simple adapter.
    To adapt to wider displays, an ACTIVE Dual-Link adapter is needed, about US$100.

  • Phone says it needs to be restored and to connect to iTunes to restore. Emergency calls only. But nothing happens when i connect it to iTunes. What's going on?

    Why can't I restore my iphone 4. it says to connect to itunes to restore and emergency calls only. But it doesn't restore.

    Reboot your computer
    Connect the USB end of the cable to a USB port directly on the computer, not a hub
    Disable your firewall and antivirus
    Launch iTunes
    Disconnect the phone from the other end of the cable
    Hold the HOME and SLEEP buttons until the screen goes black, then release the SLEEP button but contiune holding the HOME button
    Connect the cable to the phone while still holding HOME
    Wait for iTunes to recognize a phone in "recovery mode", then release HOME and your phone should restore.

  • My iPhone 5S says it's disabled and to connect to iTunes, iTunes says it needs 4 digit pass code. I tried to restore it but device wasn't recognised. Any ideas? I only got it yesterday.

    My iPhone 5S says it's disabled and to connect to iTunes, iTunes says it needs 4 digit pass code. I tried to restore it but device wasn't recognised. Any ideas? I only got it yesterday.

    How did the passcode get on the phone to begin with, if you "only got it yesterday"? Regardless, to remove it, you'll have to force the phone into recovery mode, as described here, & restore it:
    http://support.apple.com/kb/ht1808
    This will remove the passcode.

Maybe you are looking for

  • VLC player plugin conflict with Windows Media Player plugin in Firefox 8.0.1

    After I upgraded to Firefox 8.0.1, Windows Media Player stopped playing embedded videos within the Firefox browser. If you go to Add-ons and disabled VLC player plugin, Firefox will start to plays any Windows Media Player videos without any issue. Th

  • Windows  process showing up on pc free LAN - hacked? router? printer?

    In our firewall log we can see a samba connection being made from an ip on our LAN - we have no windows pcs or vritualisation software running. Our firewall is set to allow AFP + printer sharing. There is a wireless network so could someone have hack

  • Difficult: Sort Array of Prices

    Hi, i want to sort this Array in a PL/SQL Procedure: Price Start - Price End - Price Group 700 - 1200 - C 800 - 900 - B 1000 - 1200 B 1200 - 1300 A 1300 - 1700 C 1500 - 1600 B Target: 700 - 800 C 800 - 900 B 900 - 1000 C 1000 - 1200 B 1200 - 1300 A 1

  • Error Control in SAP XI

    Hi all, I´m working in a XI proyect. It is a quite simple interface, File(FTP) to proxy abap (SAP R/3). This is not a problem for me. But the customer ask for a very robusted interface, because of this they ask me to control for example if the system

  • Settlement process

    Hi experts I would like to go for brief about the settlement Process. Please explain 1. How to settle 60% to other cost objects? 2. What the industries need to follow the procedure for right periodic settlement 3. Incase in mtc order 70% work is comp