How to connect to mysql from java app

hi
please say the procedure for connecting to mysql database from java app.
.) what should i give in environmental variables
.)where can i find the driver class for the mysql
.) syntax of the url
eg:- DM.getConnection("jdbc:mysql:..............what comes here..............");

You can also get connections from a DataSource. Simple example:
            MysqlDataSource msds = new MysqlDataSource();
            msds.setUrl("jdbc:mysql://127.0.0.1:3306/dbdame");
            msds.setUser("user");
            msds.setPassword("pass");
            Connection c = msds.getConnection();Explore your options and be sure to consider connection pooling.

Similar Messages

  • How to execute Linux command from Java app.

    Hi all,
    Could anyone show me how to execute Linux command from Java app. For example, I have the need to execute the "ls" command from my Java app (which is running on the Linux machine), how should I write the codes?
    Thanks a lot,

    You can use "built-in" shell commands, you just need to invoke the shell and tell it to run the command. See the -c switch in the man page for your shell. But, "ls" isn't built-in anyays.
    If you use exec, you will want to set the directory with the dir argument to exec, or add it to the command or cmdarray. See the API for the variants of java.lang.Runtime.exec(). (If you're invoking it repeatedly, you can most likely modify a cmdarray more efficiently than having exec() decompose your command).
    You will also definitely want to save the returned Process and read the output from it (possibly stderr too and get an exit status). See API for java.lang.Process. Here's an example
    java.io.BufferedReader br =
    new java.io.BufferedReader(new java.io.InputStreamReader(
    Runtime.getRuntime().exec ("/sbin/ifconfig ppp0").
    getInputStream()));
    while ((s = br.readLine()) != null) {...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to run a makefile from java app?

    Hi,
    I want to run a make command the first time my java swing application is run. The makefile is in a directory that the application is using for input files. Do I need to write a script to house the make command or is there another way to run make?
    Thanks

    Thanks for that but I'm not actually trying to build a makefile for my java app - I just want to be able to run one that is going to generate a bunch of html files for my application to access. The make command works great from the command line but I can't just put a directory followed by "make html" in a string and run it using runtime.exec in my application.

  • [b]How connect to EJB from java webstart[/b] ?

    Hi,
    I'm a newcomer to J2EE, I'd like to build J2EEE app
    first of all,I've developed simple EJB components and jSwing client to call method from EJB. All in the same project.
    Client programe has method
    private static Context getInitialContext() throws NamingException {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
    env.put(Context.SECURITY_PRINCIPAL, "admin");
    env.put(Context.SECURITY_CREDENTIALS, "welcome");
    env.put(Context.PROVIDER_URL, "ormi://10.145.100.2:23891/current-workspace-app");
    return new InitialContext(env);
    When I run client app it work well, I follow in Jdev905 to deploy to java webstart
    1. Create .jar file (Item JAR file - Simple archive)
    2. Create Java web start(JNLP) files
    after that, I have .jar,.html,.jnlp file
    3. running project(use embedded OC4J server)
    4. running .html file
    first, java webstart download code then run but nothing
    happen. I think that It may be some wrong in JNDI look up.
    I try my best, It's taken me a week but I still do'nt understand.
    ! Please help show how to go through that or how to deploy using java web start. We intend to develop rich client.
    thanks a lots!
    Kien
    (Sorry for my bad English)

    This might be of help http://developer.novell.com/wiki/ind...asses_for_Java
    >>> dikshaneel<[email protected]> 12/8/2009 3:16 AM >>>
    Can someone please tell me how should I connect to LDAP from Java?
    Thanks in advance-- dikshaneel------------------------------------------------------------------------dikshaneel's Profile: http://forums.novell.com/member.php?userid=72973View this thread: http://forums.novell.com/showthread.php?t=395162

  • How to talk to mySql  in Java??

    Hi
    I know how to talk to Oracle and using below code:
    class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con=DriverManager.getconnection("jdbc:oracle:thin:@127.0.0.1:5013","username", "password");
    Now I use mySql database. How to connect to mySql datebase inside the java code?? Thanks
    Gary
    P.S. I only found myODBC and can't find JDBC for mySql ? what is that? how to find it?

    class.forName("oracle.jdbc.driver.OracleDriver");Connection con=DriverManager.getconnection("jdbc:oracle:thin:@127.0.0.1:5013","username", "password");
    Download the "mm" JDBC driver - the name changed since I downloaded it, but following the links from mysql.com takes you to the download section. Be sure and read the manual to be sure the example below is still accurate.
    http://www.mysql.com/downloads/api-jdbc-stable.html
    class.forName("org.gjt.mm.mysql.Driver");
    Connection con = DriverManager.getconnection( "jdbc:mysql://hostname/databasename", "username", "password");

  • How do I stop itunes from transferring apps from my ipad or iphone to my pc ?

    How do I stop iTunes from transferring apps from my iPad or iPhone to my PC ? I have App sync turn off and I have add files to library turned off. Yet every time
    I sync iTunes transfers all my apps to my PC. I have 20-30 gig of apps on each. A lot of them are 1gig each and it takes for ever to sync , plus I don't want 100 gig of apps just sitting on my hard drive for no reason. Any app I ever want is always available in the cloud so what's the point of having them on my PC in the 1st place?

    I'm pretty sure that the space is used up on your computer's hardrive.
    Anyway my solution to this nuisance of apps/itunes transfer was to allow itunes to download the apps from my phone...
    ...First of all I had tried to uncheck a few boxes in itunes a) automatically sync when device is connected (in the summary section) b) prevent devices from syncing (edit>preferences>devices) and c) Automatically sync new apps (apps section of device)
    HOWEVER, when I would click sync in any section, apps tried to transfer to itunes from my iphone.
    So after all my apps went on my computer (approx. 9 GB), I checked the boxes back, disconnected my device and deleted all the apps from itunes and my computer simultaneously (by clicking del/move to recycle bin).
    Now when I connect my iphone it does it's backup/sync thing automatically ...but no apps try to transfer
    Note: apps from your library cannot be set to sync with your device
    I can now also click sync in any section and no apps transfer.
    (This problem started when I downloaded an app from itunes rather than my device and I later transfered the app to my device. My apps section in itunes is completely empty now and no apps appear in windows explorer either)
    the only thing I am unsure of now is; what's going to happen if I purchase an app from itunes on my pc again ...I'm guessing I'll have to repeat the process (might want to avoid that)     

  • Help! How to convert an instance from java.lang.Object to a particula class

    * How to convert an instance from java.lang.Object class to a particular class
    witch is known only at the running time?
    Roster EJB component is make up of RosterHome, Roster and RosterBean.
    RosterHome is the home interface of Roster EJB.
    Roster is the remote interface of Roster EJB.
    RosterBean is the implement of Roster EJB.
    The following code segment is to invoke Roster EJB component.
    String jndiName="roster.RosterHome";
    javax.naming.Context initial = getInitialContext();//getInitialContext() returns a instance of Context.
    Object objref = initial.lookup(jndiName);
    RosterHome home =
    (RosterHome)javax.rmi.PortableRemoteObject.narrow(objref,
    RosterHome.class);
    Roster myRoster = home.create();
    String team="T1"
    String player="Tom"
    myRoster.addPlayer(player,team);
    But, now, all the home interface, the remote interface and the JNDI Name of
    Roster EJB component are not been known at the compiling time. However They are
    known at the running time, throught reading from the XML config file.
    Questions:
    1,How to write code for this case ? or
    2,How to convert an instance from Object class to a particular class witch is known
    only at the running time?
    String jndiName="roster.RosterHome";// in fact, reads from XML file.
    String homeClassName="roster.RosterHome";// in fact, reads from XML file.
    String remoteClassName="roster.Roster";// in fact, reads from XML file.
    javax.naming.Context initial = getInitialContext();//getInitialContext() returns a instance of Context.
    Object objref = initial.lookup(jndiName);
    Object objHome= javax.rmi.PortableRemoteObject.narrow(objref,
    Class.forName(homeClassName));
    /* how to do next?
    }

    I am not sure what you are trying to do. But at some point you should know which methods to call on the remote interfaces. Maybe the method names are stored in the XML file as well or you have a set of standard method names (also consider parameters).
    However, this can be solved by reflection. Look at the java.lang.reflect package, especially java.lang.reflect.Method, and also at java.lang.Class.
    If you are doing this on the app server:
    I've seen posts where people say that reflection is not permitted in EJB, but I don't think so. Check the EJB spec.
    If you are doing this in an application: reflection is always permitted. Probably also in applets and JSP.

  • How to connect to MySQL back end in Syclo Agentry?

    Hello All,
           I have worked on Syclo agentry with Non-SAP back end (MsSQL) and with SAP back end(Work Manager App).
           But now I wanted to connect with MySQL Back end, I know that it is possible, because Syclo can deal with Oracle,IBM Maximo, MsSql and SAP(ERP,CRM...etc)
           But how to connect with MySQL Back end. What is the procedure and the Configuration changes.
           Could anyone help me out to find the way.
    Thanks,
    Swaroopa.

    Swaroopa,
    You may also need to create/define your database globals if you are using SDML database tags in your queries.  For example  <<database.getSystemTime>> will evaluate differently for MySQL compared to SqlServer or Oracle
    You will want to create a mysql_sd.ini file containing the various database SDML tags and their corresponding MySql values.  I would suggest copying the sqlserver_sd.ini and then update based on mysql syntax.
    You will then want to update your Agentry.ini queryConstantFiles entry for the mySql backend settings to point to your new filename.
    --Bill

  • I have a Verizon IPhone 4 and i can't figure out how to get my ringtones from an app to my iTunes account, it doesn't have a tab for Ringtones! I have tried unplugging it and checking if would show up but it didn't, how do you enable the ringtone folder?

    I have a verizon IPhone and i can't figure out how to get my ringtones from the app to iTunes, my account doesn't have a ringtone section in the liRingtone Folder?brary, how do you enable the ringtone folder?

    Edit > Preferences.  Select the check box for Ringtones, this will add them to the listing in iTunes. 
    Not sure that really answers your question though.

  • TS1702 how do you stop itunes from downloading apps over and over again and again like for ever it wont stop  help.

    how do you stop itunes from downloading apps over and over again and again like for ever it wont stop  help.
    i tryed everything i  can in the setting and so on , i even clicked on the downloads arrow to pause it and delete them but like i said it will now stop.
    theres apps i just dont want. theres a list of them but theres not a place were i can get rid of them. it also says some stuff about icloud yeah right like i have ios 5 or 7 ha . pod touch 2 is what i have lol . plz help thanks.

    to the right by search library theres an arrow there click on it : it will show you what it is downloading , from there you can pause and select all and delete them but still will continue to download them if you tell itunes to check for downloads. that download engien is crazy i tell yeah.
    no matter what we do it will still download them trust me i tryed everything and i also went to icloud to see if it was there but to what i see is that there is no apps there this is some crazy itune program that needs to remade.

  • Hi, please how can I transfer purchases from the app store on Mac to my iPad ? I purchased  keynotes, numbers ,pages and other items. I really want to have them on my iPad . Thanks.

    Hi please how can I transfer purchases from the app store on Mac to my iPad . I downloaded  keynotes , numbers, pages and others and will want to have them on my I pad thanks.

    Apps that are written for the Mac OS cannot be used on iOS devices, such as the iPad. You can purchase the iOS versions of some of these apps in the iTunes App Store.

  • How can I purchase products from the app store while travelling outside my country of residence?

    How can I purchase products from the app store while travelling outside my country of residence? We are from Canada, travelling in the USA and wish to buy a TV series but get a message to buy it from the Canadian store. When we tried to do this we got the same message.

    According to the terms of sale, you have to be in your country of residence in order to make a purchase. I've heard of people able to make purchases outside their country and also of people being unable to do so. It appears that Apple's enforcement is not 100%.
    In order to buy from the U.S. iTunes Store, you would need to have a valid billing address in the U.S., a credit card billed to that address or an iTunes Gift card purchased in the U.S. and be physically present in the U.S. at the time of purchase.
    International copyright law is currently very inconvenient for the consumer.
    Best of luck.

  • Hello everyone!  i have a new macbook pro and i want to download aperture.  my app store says it is already installed (on my old macbook pro).  how do i install aperture from the app store in this instance please?

    hello everyone!  i have a new macbook pro and i want to download aperture.  my app store says it is already installed (on my old macbook pro).  how do i install aperture from the app store in this instance please?

    Are yoy sure that Apeture is not in the Applications folder of the new system? If it is move it to the trash and the App Store will let you download Aperture from it.
    You will need to make sure you use the same Apple ID you used to purchase it in the past.
    regards

  • HT1491 how do I purchase games from the app store with an itunes card from my device?

    How do I purchase games from the app store using an itunes card from my device?

    Redeem the card into your iTunes account and make purchases.
    Apple - iTunes - Inside iTunes - How to Redeem Free Download Codes and Gift Cards In the App Store and iTunes

  • How do I remove images from Notes app?

    How do I remove images from Notes app?
    I sometimes find that, when cutting and pasting text from the web, an image is also copied (pretty much at all times I try and avoid this, but sometimes the selection process doesn't allow for fine enough control - e.g. a whole block of content may be selected, rather than just the few words I'm trying to copy).
    I then find, once it's part of my note, that I cannot select the unwanted image and remove it. Can anyone tell me if this is something that can be done, and if so... how?
    Thanks, Sebastain

    Hi Drew & Kilgore*
    Thanks for your replies. I also have and use Simplenote, although I went off it for a while, when it started crashing all the time on me. It seems to be more stable again now, so I'll start using it more regularly again, perhaps.
    I am, obviously, disappointed that one can't simply select ANY object within a Notes document and choose to delete it. As I rather suspected, the only solution is an annoying workaround. Apple stuff seems to get more like this as time goes by. At least in my experience.
    I solved the issue my own way in the end, but I guess it was close to your 1st idea DR, and your 2nd option, KT: I basically cut and pasted everything above, and then everything below, the image, and pasted both chunks of text into a new note. So it took two passes, and left me with the original note just displaying the image, which I then trashed.
    Tapping to the right of the image followed by deletion was what I hoped & expected would work. But instead the image stayed put and the text below the cursor would simply slide along the right hand side, moving upwards as I deleted! Most bizarre, to my mind at least.
    Anyway thanks for the feedback. But, for anyone else that might want to know how to do this, the answer is: NO, you can't select and delete an image once it's in one of your notes!
    * I quite recently watched the rather strange Bruce Willis / Nick Nolte 'Breakfast of Champions' movie... I think I still prefer the book to the film!

Maybe you are looking for