MySQL Connectivity with Java

I amusing Connector/j 3.0 for jdbc through MySQL.
I am also using "org.gjt.mm.mysql.Driver"
Please suggest how to set the classpath/path for mysql driver and where to put the driver,
Please suggest with all configuration details.........

http://www.dynamic-apps.com/tutorials/classpath.jsp

Similar Messages

  • Is it possible to insert data into a MySQL database with Java?

    Hello everyone!
    I would like to know, if it's possible to insert data into a MySQL database, with a JFrame inside a servlet?
    When the JFrame is first created it calls this method:
         * Connects the servlet with the MySQL database.
        private void connect(){
            try{
                Class.forName("com.mysql.jdbc.Driver");
                connection = DriverManager.getConnection(
                        "jdbc:mysql://localhost:3306/data", "root", "omfg123");
            }catch(ClassNotFoundException cnfe){
                cnfe.printStackTrace();
            }catch(SQLException sqle){
                sqle.printStackTrace();
        }Then, when you click the "Add" button, it executes this code:
                add.addActionListener(new ActionListener(){
                    @Override
                    public void actionPerformed(ActionEvent ae){
                        String employee = employeeName.getText();
                        String[] args = employee.split(" ");
                        firstName = args[0];
                        lastName = args[1];
                        execute();
                });And this is my "execute()" method:
         * Connects the servlet with the MySQL database.
         * - And executes the SQL queries.
        private void execute(){
            try{
                PreparedStatement statement = connection.prepareStatement("insert" +
                        " into employees values(" + firstName + ", " + lastName
                        + ")");
                ResultSet result = statement.executeQuery();
                String fullName = firstName + " " + lastName;
                printer.write("Employee " + fullName + " added.</br>");
            }catch(SQLException sqle){
                sqle.printStackTrace();
        }But when I click the "Add" button, nothing happens.

    This is what I use to insert into mysql. It works on windows.
    try {
                Class.forName("com.mysql.jdbc.Driver");
                String connectionUrl = "jdbc:mysql://" + loadip + "/custsig?" +
                        "user=root&password=";
                Connection con = DriverManager.getConnection(connectionUrl);
                newproc = jTextField1.getText();
                newsoft = jTextField2.getText();
                newdeb = jTextField3.getText();
                newcust = jTextField4.getText();
                if (newcust.equals("")) {
                    errorsig12 = 1;
                    jLabel1.setForeground(new java.awt.Color(255, 0, 0));
                } else if (newsoft.equals("")) {
                    errorsig12 = 1;
                    jLabel2.setForeground(new java.awt.Color(0, 0, 0));
                } else if (newproc.equals("")) {
                    errorsig12 = 1;
                    jLabel3.setForeground(new java.awt.Color(0, 0, 0));
                } else if (newdeb.equals("")) {
                    errorsig12 = 1;
                    jLabel4.setForeground(new java.awt.Color(0, 0, 0));
                if (errorsig12 == 0) {
                    PreparedStatement ps = con.prepareStatement("insert into customer set cust_name = ?,  software = ?, processor = ?, debit = ?");
                    ps.setString(4, newdeb);
                    ps.setString(3, newproc);
                    ps.setString(2, newsoft);
                    ps.setString(1, newcust);
                    int rs = ps.executeUpdate();
            } catch (SQLException eg) {
                System.out.println("SQL Exception: " + eg.toString());
            } catch (ClassNotFoundException cE) {
                System.out.println("Class Not Found Exception: " + cE.toString());
            }

  • How to control tcp connection with java tcp socket programing ??

    Hi,
    I am connecting a server as using java socket programming.
    When server close the connection (socket object) as using close() method ,
    I can not detect this and My program continue sending data as if there is a connection with server.
    How to catch the closing connection ( socket ) with java socket programming.
    My Client program is as following :
    import java.io.PrintWriter;
    import java.net.Socket;
    public class client
      public client()
       * @param args
      public static void main(String[] args)
        Socket socket=null;
        PrintWriter pw=null;
        try
                          socket = new Socket("localhost",5555);
                          pw = new PrintWriter(socket.getOutputStream(),true);
                          int i=0;
                          while (true)
                            i++;
                            pw.println(i+". message is being send.");
                            Thread.sleep(5000);
        } catch (Exception ex)
                          ex.printStackTrace();
        } finally
                          try
                            if(pw!=null)pw.close();
                            if(socket!=null)socket.close();
                          } catch (Exception ex)
                            ex.printStackTrace();
                          } finally
    }

    I changed the code as following. But I couldn't catch the EOFException when I read from the socket. How can I catch this exception ?
    import java.io.BufferedReader;
    import java.io.EOFException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.net.Socket;
    import java.net.UnknownHostException;
    public class client
      public client()
       * @param args
      public static void main(String[] args)
        Socket socket=null;
        PrintWriter pw=null;
        BufferedReader bufIn=null;
        InputStreamReader inRead=null;
        InputStream in=null;
        try
                          socket = new Socket("localhost",5555);
                          in = socket.getInputStream();
                          inRead = new InputStreamReader(in);
                          bufIn = new BufferedReader(inRead);
                          pw = new PrintWriter(socket.getOutputStream(),true);
                          int i=0;
                          while (true)
                            i++;
                            try
                              bufIn.readLine();
                              pw.println(i+". message is being send.");
                              System.out.println(i+". message has been send");
                            } catch (Exception ex2)
                              System.out.println(ex2.toString());
                              System.out.println(i+". message could not be send");
                            } finally
                            Thread.sleep(5000);
        } catch (EOFException ex)
                          ex.printStackTrace();
        } catch (InterruptedException ex)
                          ex.printStackTrace();
        } catch (IOException ex)
                          ex.printStackTrace();
        } finally
                          try
                            if(pw!=null)pw.close();
                            if(socket!=null)socket.close();
                          } catch (Exception ex)
                            ex.printStackTrace();
                          } finally
    }

  • SAS connectivity with JAVA

    Hi,
    I have a piece of code to connect to SAS data set i have taken the drivers provided by SAS and the below code is giving error saying server not accepting userid/password but with that userid and password i can connect to SAS in other applications can any body suggest what's wrong with this.
    Driver driver=(Driver)  Class.forName("com.sas.net.sharenet.ShareNetDriver").newInstance();         System.out.println("Driver loaded");         System.out.println("JDBC:"+driver.jdbcCompliant());         String url="jdbc:sharenet://164.56.174.116:8591";         Properties credentials=new Properties();         credentials.put("user","userName");         credentials.put("password","Password");         Connection connection=driver.connect(url,credentials);         System.out.println("Connection made");         connection.close();         System.out.println("Connection closed");
    i am getting this error
    Exception in thread "main" java.sql.SQLException: Sharenet.S58.ex.txt: Sharenet.S279.ex.txt: Sharenet.S06.ex.txt: Userid/Password not accepted by server...         at com.sas.net.sharenet.ShareNetConnection.<init>(ShareNetConnection.java:219)         at com.sas.net.sharenet.ShareNetDriver.connect(ShareNetDriver.java:165)

    Once you get past actually getting a driver the configuration of it is entirely driver dependent.
    There are at least four ways that I can't think of to do use validation. There could be others. They way you have choosen, if supported at all, might be dependent on the exact name used. For example (not necessarily a solution) it could be that instead of 'user' you need 'usr' or 'User'.
    Often this involves looking at the driver documentation and just guesssing until something works.

  • Mysql connection with 1and1.co.uk

    I am trying to establish a connection with a mysql database at 1and1.co.uk but the connection cannot be established.  I have checked the login details with 1and1 and they have suggested I contact Adobe.  I am a 'design' interface user of Dreamweaver - I don't know code, so any simple suggestions would be gratefully received!

    PBrackett12 wrote:
    Ok, I think I did what I was supposed to do - although I got a bit lost.  But the result was the following when I uploaded it:  Parse error: syntax error, unexpected '=' in /homepages/41/d259550773/htdocs/oakfieldstables/login.php on line 6
    For the sake of clarity I've provided the code:
    <!-- <?php require_once('Connections/Testserver.php'); ?> -->
    <?php
    $hostname="dbXXXX.db.1and1.com";
    $database_conTestserver.php = "dbXXXX";
    $username="dboXXXX";
    $password="XXXX";
    $link = mysql_connect($hostname, $username, $password);
    if (!$link) {
    die('Connection failed: ' . mysql_error());
    else{
    echo "Connection to MySQL server " .$hostname . " successful!
    " . PHP_EOL;
    $db_selected = mysql_select_db("dbXXXX", $link);
    if (!$db_selected) {
    die ('Can\'t select database: ' . mysql_error());
    mysql_close($link);
    The $database_con variable looks incorrect
    Open up the Testserver.php in the Connections folder and look for the $database_con line. I doubt it will have .php appended to it?
    It will be like the below, right?
    $database_conTestserver = "dbXXXX";
    Amend the line in the block of php connection code and see what happens.

  • MySQL connection with CFMX

    i'm using CFMX , mysql 5.0 , mysql-connector-java-3.1.13
    how do i set the connection...
    1) do i need to add the driver into the ODBC ?
    2) do i need to set the COLD FUSION ADMINISTRATOR ? how to
    set?
    3) i had try to unzip the mysql connecter then paste into the
    C:\CFusionMX7\wwwroot\WEB-INF\lib is it correct?
    4) how can get some solution here.
    tjx

    I came across this older post. I have the same problem. I
    have followed the instruction, and tried different versions of the
    driver, but the error still comes up when I try to connect through
    CFMX7:
    "Connection verification failed for data source: MySQL_test
    java.sql.SQLException: No suitable driver available for
    MySQL_test, please check the driver setting in resources file,
    error: null
    The root cause was that: java.sql.SQLException: No suitable
    driver available for MySQL_test, please check the driver setting in
    resources file, error: null"
    If I can add any additional information so that someone can
    help me diagnose the problem, please let me know.

  • MySql connection with EJB2 project

    Hi Experts,
    I’m new in net weaver. I developed a CMP bean using EJB2 project. Now I want to connect with a table which has in MySql database. In net weaver MAXDB,ORACLE etc… options are there, but MySql is not there. So pls help me for connecting MySql.
    Thanks in Advance
    Toji.

    Hi Toji,
    I am not sure you can achieve a Container Managed Persistence if the target database is on some other machine and especially for MySQL, since SAP has their own proprietary database called MaxDB which is also a free product from MySQL AB using which we cannot even achieve a Container Managed Persistence if it installed on another machine.
    But you can achieve a Bean Managed Persistence for handling data in the MySQL database.For this,
    1) First of all, based on the version of the MySQL you will have to download the appropriate JDBC driver for MySQL.
    2) You will have to create an entry for the MySQL JDBC driver through Visual Administrator(access it from <Drive>:\usr\sap\<System ID>\JC<Instance Number>\j2ee\admin\go.bat  in the case of windows system).Here while creating the entry you will have to upload the downloaded JDBC driver.For this after login on to the Visual Administrator using the user with admin right, you will have to navigate upto,
                 Server->Services->JDBC Connector.
    3) You will have to create one Data Source. Here you will have to mention the application name , Data Source name, Driver Name( u have to select the earlier created Driver here) , Alias name, JDBC Version, Drive class, Database URL , Username and Password.
    The Driver name and Database URL u will have to mention like this.
    Driver Name -> com.mysql.jdbc.Driver
    URL            -> jdbc:mysql://<database name>
    4) In the BMP bean, you can look up the datasource like,
    InitialContext ctx = new InitialContext();
    DataSource ds = (DataSource) ctx.lookup("jdbc/<DataSource Alias Name mentioned while creating datasource in Visual Administrator>");
    Using this DataSource instance, you can create connection and execute queries.
    Just refer this help for getting knowledge on Driver creation and DataSource creation for MaxDB.
    http://help.sap.com/saphelp_nw04s/helpdata/en/42/073e1d0ab7540fe10000000a114cbd/content.htm
    Regards,
    Kishor Gopinathan

  • MySQL connection with OWB 11gR2 results in "access denied for user"

    Hello,
    I just try to establish a connection to a MySQL database with OWB 11gR2, but I always get the error "access denied for user...". I did the things written on [http://blogs.oracle.com/warehousebuilder/2010/01/owb_11gr2_mysql_open_connectivity.html] and I also used the platform configuration from this description. Newest JDBC driver was downloaded and I put the jar-file into the folder OWB_HOME/owb/lib/ext. The definition of the MySQL platform worked and the entry "MySQL" was created in OWB, but no connection can be established. I also tried other tools like MySQL Administrator in order to find out whether the problem is caused by network configuration or sth. like that, but with this tool the connection works.
    OWB is installed on OpenSuse 11.1 64bit. Does anyone know why this error occurs? Perhaps I missed some configuration tasks, which I don't know so far?
    I'm looking forward to your answers.
    Greetings
    Joerg

    Hi David,
    thank you for your reply. The corresponding user has already got this host setting. Anyway he got the wildcard '%' and with other tools I can connect.
    I solved the problem now due to just trying around with usernames. The error was quite funny: OWB changes the username always into upper case and MySQL cannot handle this username. The username must match 100% to be able to login.
    Now I just changed the user in MySQL and wrote the username in upper case. But in fact I would like to know if it is possible to avoid that OWB changes the username, with quotes it didn't work ;-)
    Greetings
    Joerg
    UPDATE:
    Now I'm facing another problem: the connection works, but I cannot import any metadata. When I click on "Browse" to select the correct schema in MySQL DB, no result is displayed. The user anyway has go the privileges to select data from this schema. I also tried to provide the user with every possible privileges for this schema, but I still cannot select any schema. When I write the schema manually and then try to import database objects iin OWB the error message "definitions of userdefined metadata interface are invalid" is displayed (translated from german, so the wording could be different). Does anybody have an idea what the problem could be?
    Edited by: Scantid on 15.01.2010 00:41

  • Filenet connection with java api not working

    I have written the following code to connect content engine and process engine..
    MY content engine is connected fine and good...But process engine is not connecting
    code:
    public String PE_CONNECTION_POINT      = "PEConnection";
    public Connection ceConnection;
    public Domain ceDomain;
    public void testFileNetConnection()
    * Connect to Content Engine and retrieve a list of
    * properties for the base 'Document' document class
    ceConnection =
    Factory.Connection.getConnection(FILENET_URI);
    Subject ceSubject =
    UserContext.createSubject(ceConnection, FILENET_USERNAME, FILENET_PASSWORD, null);
    UserContext.get().pushSubject(ceSubject);
    ceDomain = Factory.Domain.fetchInstance(ceConnection, CE_DOMAIN, null);
    ObjectStore ceObjectStore = Factory.ObjectStore.fetchInstance(ceDomain, CE_OBJECTSTORE, null);
    ClassDefinition classDef =
    Factory.ClassDefinition.fetchInstance(ceObjectStore, "pawan", null);
    PropertyDefinitionList properties = classDef.get_PropertyDefinitions();
    for (Iterator propertyIter = properties.iterator(); propertyIter.hasNext();) {
    PropertyDefinition property = (PropertyDefinition) propertyIter.next();
    System.out.println("Property: " + property.get_DisplayName());
         //this.instantiateFolder(ceObjectStore);
         //this.createFile(ceObjectStore, ceDomain);
    UserContext.get().popSubject();
    * Connect to Process Engine and retrieve a list of
    * Queues for this Connection Point
    VWSession peSession = new VWSession();
    peSession.setBootstrapCEURI(FILENET_URI);
    String[] queueNames = null;
    try
         peSession.logon(FILENET_USERNAME ,FILENET_PASSWORD,PE_CONNECTION_POINT);
         queueNames =
         peSession.fetchQueueNames(VWSession.QUEUE_PROCESS);
    catch(Exception es){es.printStackTrace();}
    for (String queue : queueNames)
    System.out.println("Queue: " + queue);
    The output of above code I have attached part of successful connection of the content engine and the error of process engine
    Property: Ignore Redirect
    Property: Entry Template Object Store Name
    Property: Entry Template Launched Workflow Number
    Property: Entry Template Id
    java.lang.NoClassDefFoundError: com/ibm/CORBA/iiop/ObjectURL
         at filenet.pe.peorb.client.ORBSession.establishORBSession(ORBSession.java:667)
         at filenet.pe.peorb.client.ORBSession.<init>(ORBSession.java:985)
         at filenet.vw.server.PECommandsFactory.getPECommands(PECommandsFactory.java:119)
         at filenet.vw.api.VWSession.logonByDomain(VWSession.java:864)
         at filenet.vw.api.VWSession.logon(VWSession.java:723)
         at FileNetConnectionTest.testFileNetConnection(FileNetConnectionTest.java:97)
         at FileNetConnectionTest.main(FileNetConnectionTest.java:35)
    Caused by: java.lang.NoClassDefFoundError: com/ibm/CORBA/iiop/ObjectURL
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at com.ibm.websphere.naming.WsnInitialContextFactory.init_implClassCtor(WsnInitialContextFactory.java:172)
         at com.ibm.websphere.naming.WsnInitialContextFactory.getInitialContext(WsnInitialContextFactory.java:112)
         at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
         at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
         at javax.naming.InitialContext.init(Unknown Source)
         at javax.naming.InitialContext.<init>(Unknown Source)
         at filenet.pe.peorb.client.ORBServiceHelper.getORB(ORBServiceHelper.java:442)
         at filenet.pe.peorb.client.ORBServiceHelper.initFromORBRouterInfo(ORBServiceHelper.java:286)
         at filenet.pe.peorb.client.ORBServiceHelper.<init>(ORBServiceHelper.java:873)
         at filenet.pe.peorb.client.ORBSession.establishORBSession(ORBSession.java:653)
         ... 6 more
    Exception in thread "main" java.lang.NullPointerException
         at FileNetConnectionTest.testFileNetConnection(FileNetConnectionTest.java:104)
         at FileNetConnectionTest.main(FileNetConnectionTest.java:35)
    When to remove the above error I add IBMORB.jar in enviroment variable then I get following error
    log4j:WARN The log4j system is not properly configured!
    log4j:WARN All ERROR messages will be sent to the system console until proper configuration has been detected.
    Exception in thread "main" com.filenet.api.exception.EngineRuntimeException: SECURITY_INVALID_CREDENTIALS: Invalid credentials.
         at com.filenet.apiimpl.wsi.ClientOperation.getCredential(ClientOperation.java:303)
         at com.filenet.apiimpl.wsi.ClientOperation.setCallContext(ClientOperation.java:194)
         at com.filenet.apiimpl.wsi.ClientOperation.start(ClientOperation.java:102)
         at com.filenet.apiimpl.wsi.ClientOperation.run(ClientOperation.java:69)
         at com.filenet.apiimpl.wsi.ServiceSession.getObjects(ServiceSession.java:242)
         at com.filenet.apiimpl.util.SessionHandle.getObjects(SessionHandle.java:334)
         at com.filenet.apiimpl.core.Session.callGetObjects(Session.java:121)
         at com.filenet.apiimpl.core.Session.executeGetObject(Session.java:325)
         at com.filenet.apiimpl.core.Session.getObject(Session.java:339)
         at com.filenet.apiimpl.core.IndependentObjectImpl.getObject(IndependentObjectImpl.java:154)
         at com.filenet.apiimpl.core.IndependentObjectImpl.refresh(IndependentObjectImpl.java:161)
         at com.filenet.api.core.Factory$Domain.fetchInstance(Factory.java:1543)
         at FileNetConnectionTest.testFileNetConnection(FileNetConnectionTest.java:69)
         at FileNetConnectionTest.main(FileNetConnectionTest.java:35)
    Plz help me out..Thank you

    I'm having the same problem.. I think there's something wrong with it. [fast weight loss tips|http://www.weightlossgidiet.com]

  • MS Olap connection with java api

    Hi,
    I am new to sql 2005 analytical server. How to connect to the sql 2005 analytical server using java programming language. If any one of you know please let me know details with some sample code

    If you are going to post code please use the code formatting tags. Select the code you are posting in the message box and click the CODE button.
    Your error is here
    Problem getting JAAS Context: java.lang.SecurityException: Unable to locate a login configurationYou should look into that.

  • Crystal Report Connectivity with Java

    How to connect our program with crystal report?

    I have never used crystal report. I have created a stand-alone application in java 6 with SQL server 2000 as backend. Its a simple application that maintains records of employees in an organization. I want to use crystal report for report generation. I have crystal report 9 on my system. I have searched a lot on google but could not find any relevant help. Can u provide help in this regard or send me links from where i could get any lead.
    I am not using any IDE as such now. Is it actually needed?
    Any help in this regard would be highly appreciated.

  • Database connectivity with java!

    hello, has anyone got a "detailed" tutorial they can send on:
    1.setting up mySQL database (not just install)
    2.setting up J/connector (not just install)
    3.a tutorial on how i can get a servlet to interact with a client through a webpage!
    does it sound like i'm trying to learn how to do 5things at once? well your right... i want to start small, but i need to learn SQL to set up a database, and i need to j/connector to interact with the database.
    i'm less worriered about the third point at the moment, because there is a sun tutorial i've been looking at!
    any help would be more then appreciated!

    1.) use the mySQL documentation (it's not that bad)
    2.) see the j2ee tutorial (http://java.sun.com/j2ee/1.4/docs/tutorial/doc/ - chapter 11 is about servlets)
    3.) learn something about HTML and HTML formulars, your servlet could interpret the parameters transmitted from formulars (by HTTP GET, HTTP POST, ...)
    4.) discover the API documentation for the packages javax.servlet and javax.servlet.http to learn more about the possibilities
    5.) try it out (e.g. create a servlet which presents all the servlet parameters which are available: servlet information, request information, response information, ...)
    6.) have fun!
    hope it helps...

  • Mysql connect to java

    i have a rt.jar file to connect java to mysql database

    i have a rt.jar file to connect java to mysql database

  • Foxpro connectivity with java

    can any body tell me how to connect the foxpro (.dbf) file with my java program. i have already tried this
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:dsn_foxpro", " ", " ");
    but this work only for the whole database not for a single table within it, can any body help me in solving this problem

    The Foxpro ODBC lets you set up a DSN for either a database or free table. Try setting up a DSN for just that table.
    I have found though, that even if you have a DSN set up for a database, you can still do selects off of a single table.

  • Mysql connection with JDBC

    I have followed the advice given here for several
    other people and have successfully set up a connection
    to a MySQL database. I can successfully test the
    database connection from the Connection Wizard.
    However, I am having trouble accessing this same
    connection from my code. When executing the following
    piece of code:
    try
              Class.forName("org.gjt.mm.mysql.Driver");
    I get a ClassNotFoundException.
    The advice in the JDeveloper "help" is not that clear.
    I have tried registering this driver with the project,
    by configuring the connection as a library and adding
    this library into the "Project Settings". I've also
    added in the database connection in Tools->Preferences.
    Finally, I've tried using File->Import->Existing Sources
    and choosing the library I created for the mysql Jar
    file. None of this works... am I following the correct
    procedure, or is there something I've missed?

    the mysql jdbc driver : org.mm.mysql.Driver (you can find it on www.gjt.org)
    the url : jdbc:mysql://host:port/dbname
    obtain a connexion:
    Class.forName("org.mm.mysql.Driver");
    Connection conn = DriverManager.getConnection(url, "username", "password");

Maybe you are looking for

  • My MacBook Pro(early 2011) not turning on

    I've had this mac for 5 months already, hasn't given me a problem until now. It was working fine when I used it this morning. I left it plugged in and went to work. So when I came back from work, I tried to turn it on but it doesn't. Every time I pre

  • Deploying  pdk, i have some trouble in sdm

    hi   i download pdk6.0_60_3 for ep6.0sp4. the content of pdk is the format of .sca. i want to deploy the .sca file by software delivery manager( /usr/sap/EPDEV/java/sdm/program/startSDM.sh ). when i choose the "add swc/sda/sca to deployment list", in

  • I am currently in the middle of a cross platform swap

    I got Photoshop CS6 from a digital download and I need to find the serial number on my PC to submit it and get the program on my MAC

  • What happened to the Inspector in Pages

    My (Editing features - Inspector, Media, and something else) disappeared.  I need it desparately.  I do I retrieve them? Sandy

  • One installer and multiple users

    I copied the Lion installer to a flash drive and I have a few different users at work that I want to upgrade. Can they buy Lion in the app store and then stop the download and use my copied installer to install Lion? Will there be any conflicts with