Connectivity with MySQL in Windows

How can I connect JSP with MySQL in Windows?
          I Tried out the following code but It did not work
          Class.forName("org.gjt.mm.mysql.Driver");
          Connection cn = DriverManager.getConnection("jdbc:mysql:///test");
          

I think you missed the IP address for your MySQL server machine.
          If it's on the same computer, try this:
          jdbc:mysql://localhost/test
          "John Jacob" <[email protected]> wrote in message
          news:[email protected]..
          > How can I connect JSP with MySQL in Windows?
          > I Tried out the following code but It did not work
          >
          > Class.forName("org.gjt.mm.mysql.Driver");
          > Connection cn = DriverManager.getConnection("jdbc:mysql:///test");
          

Similar Messages

  • Java connection with mysql

    Anybody please help me:
    I creating java application that comunicate with the mysql database. I use JConnector and all work find.
    My problem is when i compile the program into JAR file and when i run it(double click the file), i saw my application but the connection with the mysql database is not successfull. i try to search from internet, and i found that i must put my JConnector inside the jdk1.3.1/jre/lib/ext.
    Once i put that the program can run and the connection is fine, but only if i run it from the dos by typing the command c:\java -jar turkeySystem.jar.
    So anybody can advise me, what should i do if i want to make my application run smoothly and connected with the database, without having the dos run at the background. (just double click the jar file).
    i don't have problem to run that if i using ms access as a database.
    Thank you in advanced.

    if it runs with "java -jar turkeySystem.jar." you have a valid manifest.mf in your jar. so it can basically be executed by double clicking it --- if the JDK is installed correctly. otherwise you need to change the datatype handling in windows by adding "java -jar %1" as the command for the file suffix ".jar". this is the case if you e.g. just copy your Java SDK folder to a computer and didn't install it with the windows exe java wizard.

  • Connection with mysql

    Hi all!
    I am trying to connect MySql using connector mysql-connector-java-3.0.17-ga-bin.jar. Driver is loaded but it is
    not getting connected. Though in Windows it works fine but give problem in linux fedora 6. I am using connection string
    jdbc:mysql://localhost:3306/test with username and password.
    code --------
    System.out.println("before driver loading");
    String url="jdbc:mysql://localhost:3306/test";
    //load JDBC driver
    try
    Class.forName("org.gjt.mm.mysql.Driver");
    System.out.println("driver loaded");
    catch(Exception e)
    System.out.println("Uable to load driver.");
    try
    System.out.println("Trying to make connections");
    Connection conn=DriverManager.getConnection(url,"username","password");
    System.out.println("Database connected");
    Statement stmt=conn.createStatement();
    ResultSet rs=stmt.executeQuery("select * from table");
    while (rs.next())
    System.out.println(rs.getString(1));
    catch (SQLException e)
    System.out.println("SQLException:"+e);
    It shows following error-
    SQLException:java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.SocketException: java.net.ConnectException: Connection refused
    ** BEGIN NESTED EXCEPTION **
    java.net.SocketException
    MESSAGE: java.net.ConnectException: Connection refused
    STACKTRACE:
    java.net.SocketException: java.net.ConnectException: Connection refused
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:143)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:1805)
    at com.mysql.jdbc.Connection.<init>(Connection.java:452)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
    at java.sql.DriverManager.getConnection(DriverManager.java:525)
    at java.sql.DriverManager.getConnection(DriverManager.java:171)
    at Check.main(Check.java:27)
    ** END NESTED EXCEPTION **
    Whats wrong?

    That is an ancient Driver (both classname and jarfile). Download a new driver and use "com.mysql.jdbc.Driver".
    That is beside the point though. The real point is that it seems as though your mysql is not configured to accept network connections, or it is configured for a different port from the default 3306. Check your configuration, see the documentation for details.

  • Problem in establishing connection with mysql 5.0

    Hi,
    I am using JCAPS 5.1. I tried to insert data to mysql database table.
    But i got following error
    java.sql.SQLException: Error in allocating a connection. Cause:
    Physical Connection doesn't exist.
    My intention is to read file in which data are comma seperated and to
    populate those values to a mysql 5.0 database table.
    Sample DATA in file [test.txt]
    111,gg,23,MFG
    112,hh,24,MFG
    113,ii,25,RETAIL
    114,jj,26,IT
    Database table: employee
    eno,ename,eage,edept
    While creating JDBC OTD there is no problem in establishing connection with database. But after deploying i got above error.
    I have used Mysql 5.0 Connector/J JDBC driver. Added JDBC driver jar files to following directories as required.
    1) C:\JavaCAPS51\logicalhost\is\lib
    2)C:\JavaCAPS51\logicalhost\is\domains\test\lib
    Steps i have followed as per JDBC-ODBC -eway user guide doc.
    1) Created USerDefined OTD and added necessary fields
    2) Created JDBC OTD.
    3) Created JAVA collaboration and do business process for inserting
    4) Mapped all components by creating in Connectivity MAp
    5) created necessary external systems in envrionment explorer.[JDBC External System and File External System]
    6)Created Deployment profile
    5) Deployed it.
    After deploying it gives error as
    java.sql.SQLException: Error in allocating a connection. Cause: Physical Connection doesn't exist
    Please let me know the solution for problem.
    Message was edited by:
    VenkateshSampoornam

    In the environment definition,
    -> External Application JDBC
    -> Properties
    -> Outbound JDBC Connection
    You have the database URL in the "DriverProperties" field
    Valid URL would be : jdbc:mysql://localhost:3306/caps
    !! The doc says that this field is optional !! Seems to be an error in the doc:
    Hope this helps
    Seb

  • Create a simple connection with mysql

    hello
    my name is edvanio i am from brazil.
    i'd like to connect one program in Java with mysql for insert, delete and update one simple base ex. teste with nome and fone.
    thank , bye

    here's a couple of sites
    http://www.javacoding.net/articles/technical/java-mysql.html
    http://www.developer.com/java/data/article.php/3417381
    I recently installed MySQL (just to see if I could get a working program to run)
    these were the steps
    1. downloaded MySQL
    2. downloaded the connector file
    3. unzipped/installed MySQL
    4. unzipped the connector file
    mysql-connector-java-3.0.17-ga-bin.jar
    copied the jar file into this directory
    C:\Program Files\Java\jdk1.5.0_03\jre\lib\ext
    5. opened MySQL, using the code from Gamelan
    create the db JunkDB
    created the user, permissions, password
    6. combined the code from both sites (code follows)
    and it worked OK
    import java.sql.*;
    class MySQL_Test
      public MySQL_Test() throws Exception
        testDriver();
        Connection con = getConnection();
        executeUpdate(con,"CREATE TABLE test(id int,text varchar(20))");
        executeUpdate(con,"insert into test(id,text) values (1,'first entry')");
        executeUpdate(con,"insert into test(id,text) values (2,'second entry')");
        executeUpdate(con,"insert into test(id,text) values (3,'third entry')");
        executeQuery(con,"select * from test");
        executeUpdate(con,"drop table test");
        con.close();
      protected void testDriver() throws Exception
        try
          Class.forName("com.mysql.jdbc.Driver");
          System.out.println("MySQL Driver found");
        catch(ClassNotFoundException cnfe)
          System.out.println("OOPs - MySQL Driver nowhere to be found");
          throw (cnfe);
      protected Connection getConnection() throws Exception
        String url = "";
        try
          url = "jdbc:mysql://localhost:3306/JunkDB";
          Connection con = DriverManager.getConnection(url,"auser","drowssap");
          System.out.println("Connection OK");
          return con;
        catch(SQLException sqle)
          System.out.println("OOPs - No Connection");
          throw (sqle);
      protected void executeUpdate(Connection con,String sqlStatement) throws Exception
        try
          Statement s = con.createStatement();
          s.execute(sqlStatement);
          s.close();
        catch(SQLException sqle)
          System.out.println("OOPs - error executing statement");
          throw (sqle);
      protected void executeQuery(Connection con,String sqlStatement) throws Exception
        try
          Statement s = con.createStatement();
          ResultSet rs = s.executeQuery(sqlStatement);
          while(rs.next())
            String id = (rs.getObject("id").toString());
            String text = (rs.getObject("text").toString());
            System.out.println("Found record "+id+" "+text);
          rs.close();
        catch(SQLException sqle)
          System.out.println("OOPs - error executing resultset");
          throw (sqle);
      public static void main(String[] args)
        try
          new MySQL_Test();
        catch(Exception e){e.printStackTrace();}
    }

  • Create database connection with Mysql

    Hi, all:
    inside JDeveloper, i try to create a database connection for Mysql (third party
    JDBC driver). I input all needed parameters into
    JDeveloper database connection dialog, and test connection, the error message
    says 'Unable to find driver org.gjt.mm.mysql.Driver". The jar file contains driver
    is listed in system classpath, and Mysql and MM-Mysql JDBC driver are tested with
    other applications and there is no problem.
    So, what i should do to create such a connection ??
    Any help will be appreciated. thank you in advance.
    kevin.

    The connectio URL could look like this:
    (leave the User-, Password-, and Role-fields, in the tab before, empty)
    Java Class Name: org.gjt.mm.mysql.Driver
    URL: jdbc:mysql://localhost:3306/test?ultradevhack=true&?user=myuser&?password=mypassword

  • How connect with mysql 5

    hi master
    sir i am use studio creator now i install the mysql5
    sir please give me idea how i connect my studio creator with mysql 5
    thank
    aamir

    hi
    follow the following steps:
    1) Download Jconnector Driver for java from www.mysql.com
    2) Open the creator , from servers palette select data source and right click.
    3) choose new data source , click new
    4) select the jar file u downloaded from the web site.
    5)clicj suggeste ( this will make the creator to select connections statments automatailcly )
    6) put the username and password and click ok
    this will make a datasource with mysql server.
    be sure that the mysql server is run,, and make sure that u apply right username and password
    Hope this will help
    Good luck
    Mohammed

  • Connecting with mysql

    hello
    how can i create a connection to mysql and postgresql databases in jdbc. without using odbc.
    thanks.

    You need to use a different driver. I assume you're using the jdbc-odbc bridge driver.
    For mysql, get the mm.mysql driver at http://mmmysql.sourceforge.net/
    For postgresql, go to http://jdbc.postgresql.org/
    I've only used the mysql driver, so I don't know the details of how to use the postgresql one.
    In general, you will have to do the following:
    1. download the jar file and put it in your classpath
    2. change the connection url string to conform with the format in the driver documentation.

  • Jar file connection with mysql

    Hello everyone i ve a problem if you people could solve please help...
    When i compile my java code with mysql connection it works perfectly, but when i convert into jar file its not updating any values in the mysql database
    Can anyone tell me a solution.

    subhavenkatesh wrote:
    Can anyone tell me a solution.You have a bug. Find it. Fix it.

  • Facing problem of not getting Bluetooth periferal device to connect with my computer windows 7 on Del studio 1555 model

    I am facing problem for connecting with my windows 7
    My blackberry Q10 not conecting properly,elerts displaying on computer you have not Bluetooth Periferal device driver
    installed,I am not getting same on internet searching

    I am sorry, but to get your issue more exposure I would suggest posting it in the commercial forums since this is a commercial printer. You can do this at http://h30499.www3.hp.com/hpeb/
    I hope this helps.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • Problem with USERNAME & PASSWORD creation--JDBC connection with MYSQL

    How to connect to JDBC with Mysql Connector
    i installed mysql & created table, it works fine
    During Password---> I gave it as tiger , no username
    i installed mysql connector
    i saved the .jar file path in class path
    HOW TO CREATE USERNAME & PASSWORD & DATASOURCE NAME ---> Is it the password -tiger or something else like (ADMinstrative tools-ODBC-services--etc )
    Pl, help,
    tks
    Xx

    How to connect to JDBC with Mysql Connector
    i installed mysql & created table, it works fine
    During Password---> I gave it as tiger , no usernameTiger? This ain't Oracle.
    I think you should give a username and password. How can it look up a password without a username? Better GRANT the right permissions, too.
    Read the MySQL docs a bit more closely. Your path isn't the way to go.
    %

  • Jakarta-tomcat-3.3.2 connection with mysql-4.1.12a-win32

    how do i connect to mysql using tomcat?
    i've set the class path = ".;D:\j2sdk1.4.2_08\jre\lib\ext\mysql-connector-java-3.1.10-bin.jar;"
    without quotes
    i've copy the mysql-connector-java mysql-connector-java-3.1.10-bin.jar into the mentioned directory = "D:\j2sdk1.4.2_08\jre\lib\ext\"
    and my computer's mysql 's service is starting since my computer restart [i've checked it by right click desktop toolbar->Task Manager->Processes->mysqld-nt.exe..
    and i've used the code from :
    http://www.stardeveloper.com/articles/display.html?article=2003090201&page=4
    to test if my connection is active, my JdbcExample1.java file is located at D:\jakarta-tomcat-3.3.2\webapps\ROOT\WEB-INF\classes\com\example, so my source code is :
    package com.example;
    import java.sql.*;
    public class JdbcExample1 {
      public static void main(String args[]) {
    Connection con = null;
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql:///test", "root", "nothing");
    if(!con.isClosed())
    System.out.println("Successfully connected to MySQL server...");
    } catch(Exception e) {
    System.err.println("Exception: " + e.getMessage());
    } finally {
    try {
    if(con != null)
    con.close();
    } catch(SQLException e) {}
    when i compile the file using javac, it's fine, when i run it using java, it shows me this error:
    Exception in thread "main" java.lang.NoClassDefFoundError: JdbcExample1 (wrong n
    ame: com/example/JdbcExample1)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
    3)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
    what have i missed out? anyone can u please help me? is my coding or setting in-accurate? thanks for reviewing my topics too

    I'm not sure why you have mentioned Tomcat, but you need to run the class with something like:
    java -classpath .;D:\j2sdk1.4.2_08\jre\lib\ext\mysql-connector-java-3.1.10-bin.jar com.example.JdbcExample1If you've correctly set the CLASSPATH environment variable then you can leave out the -classpath command line argument. Notice that you must specify the package of the class too.
    To compile this all correctly, you should do something like:
    mkdir classes
    javac -d classes JdbcExample1.javaand then run with
    java -classpath classes;D:\j2sdk1.4.2_08\jre\lib\ext\mysql-connector-java-3.1.10-bin.jar com.example.JdbcExample1

  • Slow database connection with mysql

    I am using MySQL Server 5.0 as my backend and java1.5 as my front end for the GUI. The following statements I use to connect to MYSql.
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    String url = "jdbc:mysql://localhost:3306/mysql";
    The database access seems to be very slow.
    I have a data file with about 3000 lines. The parser reads the file one line at a time, formats an insert query and calls executeUpdate. The process takes more than 2 minutes.
    What is slowing down my process? Please help
    Thanks

    I am using MySQL Server 5.0 as my backend and java1.5
    as my front end for the GUI. The following statements
    I use to connect to MYSql.
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    String url = "jdbc:mysql://localhost:3306/mysql";
    The database access seems to be very slow.
    I have a data file with about 3000 lines. The parser
    reads the file one line at a time, formats an insert
    query and calls executeUpdate. The process takes more
    than 2 minutes.
    What is slowing down my process? Please help
    ThanksHi,
    1. Are you opening and closing the database connection ,During inserting every record from data file?
    If so, please avoid opening closing connection for each query execution.
    Because , opening and closing the database connection is a time consuming one.
    You should open all the required database connections, before you use them or use
    Database connection pooling if your application is sucah a big one.
    2. Try PreparedStatment instead of Statement. Because Prepared statment query is
    compiled and stored into Cache. so if you are executing the same query again and again, the compiled query will be picked up from cache, by replacing with new
    parameters
    3. Check the logic you used to pick record from datafile and insert into database .
    4. Check your RAM size , if you installed database and jvm on same machine.
    if so , increase your RAM size.
    thanks,
    nvseenu

  • External connection with MYSQL db

    Hi to all,
    i need to make an external connection to MYSQL database with "EXEC SQL" instruction of abap/4.
    I've already maintained the DBCON table: i've created a new external connection (called TEST1), but i don't really know how to valorize the DBMS (db type) and CON_ENV (connection instructions) fields .
    For MSSQL is simple (there are many examples on this forum), but for MYSQL db?? I wasn't able to find posts about configuring it.
    Is there this kind of connection possible. What are other "way" to make this connection? I'd like to select/insert/update some table rows
    Helpfull answer will surely good rewarded
    Thx a lot in Advice
    Andrea Galluccio

    Hi
    For MSSQL , we give the Connection Information as just MSSQL_SERVER=<ServerName>. But for MYSQL and oracle the parameters differ.
    Just check out http://www.irietools.com/iriepascal/progref125.html
    I am not quite sure abt it.

  • Connection with MYSQL ODBC

    Post Author: wrkwinter
    CA Forum: Data Connectivity and SQL
    Hi,   I am having problem with conecting Crystal Report XI to the MYSQL Server. I am using Mysql Connector/ODBC 3.51. I configured ODBC connection . Once i connect to MYSQL server thru Crystal Rpeort Everything works fine but after 5-10 minutes if i refresh the report I get following error.
    "Failed to retrieve data from the database"DetailsHY000:&#91;MySQL&#93;&#91;ODBC 3.51 driver&#93;&#91;mysqld-4.1.22-standard-log&#93;&#91;MySQl server has gone away&#91;Database vendor code :2006&#93; and if i log off and relog on to database everything works fine like for another 5-10 minutes and after that same ERROR  But if i use MYSQL Query Browser to connect to the database. I don't have any problem like that.  Can please explain any reason for that.....Thanks

    Post Author: synapsevampire
    CA Forum: Data Connectivity and SQL
    Check out:
    http://www.mysqltalk.org/server-has-gone-away-vt158777.html
    I'd guess that you're timing out or exceeding the number of connections.
    -k

Maybe you are looking for