Results 1 to 19 of 19
  1. #1
    Amit20 is offline Member
    Join Date
    Feb 2011
    Posts
    6
    Rep Power
    0

    Default Connection with MySQL

    Hello Friends.

    I have been working with Java and MS-SQL Server 2005. Now i want to connect to MySQL.
    I have downloaded JConnector driver for MySAL but dont know how to install it.

    I read the instructions on MySQL website but still could'nt installed it.

    So can anyone please explain me.

    Any help will be highly appreciated!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default

    You don't install it.
    You include it as part of your app.

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Do you know what you did in order to use the SQL Server jdbc driver? Do the same for the MySQL driver.

  4. #4
    Amit20 is offline Member
    Join Date
    Feb 2011
    Posts
    6
    Rep Power
    0

    Default

    What i did with MS-SQL is install it and then create a DSN for my database using ODBC. But i don't understand how to configure JConnector so that i can create a DSN!

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default

    You don't use ODBC for this.
    The docs for JConnector will tell you what the connection syntax is for your getConnection call.

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by Amit20 View Post
    What i did with MS-SQL is install it and then create a DSN for my database using ODBC. But i don't understand how to configure JConnector so that i can create a DSN!
    Then that was your first mistake, I'm sorry to say.

  7. #7
    Amit20 is offline Member
    Join Date
    Feb 2011
    Posts
    6
    Rep Power
    0

    Default

    Its ok. ThaNK YOU FOR YOUR HELP.
    ATLEAST I M LEARNING SOMETHING.

  8. #8
    f22raptor is offline Member
    Join Date
    Aug 2011
    Posts
    16
    Rep Power
    0

    Default Re: Connection with MySQL

    What u need to do is you have to download the mysql connector.jar and place that jar file in your lib folder of jdk. then you need to copy the path of the jar that will be like c://program files/java/jdk1.5/lib/mysqlconnect.jar and paste it beside the classpath of ur jdk by using semicolon in the environment variables. then when you write your jdbc code you have specify the location of ur database server by declaring a string url and giving it a value jdbc:mysql://localhost:3306/yourdatabasename. and then when you open the connection pass the same url followed by the username and password as parameters to the DriverManager.getConnection method.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default Re: Connection with MySQL

    Quote Originally Posted by f22raptor View Post
    What u need to do is you have to download the mysql connector.jar
    No...that won't work, as they are using SQL Server.

    Quote Originally Posted by f22raptor View Post
    and place that jar file in your lib folder of jdk.
    No, you should never put extra stuff in your JDK lib folder.

    Quote Originally Posted by f22raptor View Post
    then you need to copy the path of the jar that will be like c://program files/java/jdk1.5/lib/mysqlconnect.jar and paste it beside the classpath of ur jdk by using semicolon in the environment variables.
    No, that's not the recommended way of handling a Java apps classpath. You place your driver jar file in with your other libs associated with your project. That way you'll have no problems if one project needs an upgraded jar file, but another doesn't.

    Quote Originally Posted by f22raptor View Post
    then when you write your jdbc code you have specify the location of ur database server by declaring a string url and giving it a value jdbc:mysql://localhost:3306/yourdatabasename. and then when you open the connection pass the same url followed by the username and password as parameters to the DriverManager.getConnection method.
    This is possibly the only correct thing, albeit for the wrong database.

  10. #10
    f22raptor is offline Member
    Join Date
    Aug 2011
    Posts
    16
    Rep Power
    0

    Default Re: Connection with MySQL

    [QUOTE=Tolls;234906
    No, you should never put extra stuff in your JDK lib folder.



    No, that's not the recommended way of handling a Java apps classpath. You place your driver jar file in with your other libs associated with your project. That way you'll have no problems if one project needs an upgraded jar file, but another doesn't.



    But what if i want to run the jdbc independently. In clear words, like i have no projects and yesterday i tried to run one simple jdbc program for my mysql database and i got this suitable driver not found error for which am still working on it to resolve it. What i mean to ask is that suppose i write a simple jdbc program and try to run that program through command prompt shouldn't for that case the jar file should be placed in jdk/lib folder???

    Thank you.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default Re: Connection with MySQL

    You can't run it independently.
    JDBC is a framework for building apps, not an app in itself.
    And if you are building an app, then you need to give the app any librarise it depends on.
    When running the app, you supply a classpath (usually using -cp) to those libraries.

  12. #12
    f22raptor is offline Member
    Join Date
    Aug 2011
    Posts
    16
    Rep Power
    0

    Default Re: Connection with MySQL

    okay so you mean to say that i need to mix the jdbc with my webapp even if i need to test my jdbc connection and paste the mysql connector jar file to the lib directory of my web project and set the classpath accordingly???

    Thank you.

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default Re: Connection with MySQL

    I don't know how you are writing your apps, but the jar file would be part of your WAR that would be dropped into your server.
    Most servers pick up the jar files contained in the WEB-INF/lib directory as part of the classpath fro a web-app.

    As for "mix the jdbc in", it is (presumably) part of your web app. If it is intended for multiple apps then write it as a seperate module and test that.

  14. #14
    f22raptor is offline Member
    Join Date
    Aug 2011
    Posts
    16
    Rep Power
    0

    Default Re: Connection with MySQL

    No actually since this is my first stint with jdbc what i was trying to do was write code in note pad, copy the jar file to jdk/lib because this is how i came across in some web site and then run the program using the command line by javac and my filename and so on. Though i have tomcat installed i had no intention of that.

    But anyways thanks for the enlightenment, tonight i will try by your method.

    Thank you once again.

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default Re: Connection with MySQL

    Then you ought to have the libraries you need in a directory along with the code you're working on:
    Java Code:
    MyAppDirectory ->
        lib (contains any jars you need)
        mytoppackage -> etc etc.
    And, running from MyAppDirectory on the command line:
    java -cp .;lib/*.jar mytoppackage/MyProgramClass

  16. #16
    f22raptor is offline Member
    Join Date
    Aug 2011
    Posts
    16
    Rep Power
    0

    Default Re: Connection with MySQL

    Actually i got it!!! The thing that i learned was that it is all about setting the class path right!!! What exactly had happened was i had created a classpath variable and assigned it the java path followed by my mysqlconnector.jar path in the environment variables.

    But after some time i found out that there was already a variable named path defined in the enivronment variables. so i removed my custom classpath and assigned both the java classpath and mysql connector.jar path to the path variable and it is working....:)

    So its about setting your path straight.

    Thank you any ways for the assistance.

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default Re: Connection with MySQL

    Don't use environment variables either.
    Your application classpath is specific to your application, not your machine as a whole.
    It's a bad habit to get into to put this stuff onto your system (or user) classpath.

  18. #18
    f22raptor is offline Member
    Join Date
    Aug 2011
    Posts
    16
    Rep Power
    0

    Default Re: Connection with MySQL

    Thanks you

  19. #19
    naved is offline Member
    Join Date
    Apr 2011
    Posts
    7
    Rep Power
    0

    Default Re: Connection with MySQL

    Quote Originally Posted by Amit20 View Post
    Hello Friends.

    I have been working with Java and MS-SQL Server 2005. Now i want to connect to MySQL.
    I have downloaded JConnector driver for MySAL but dont know how to install it.

    I read the instructions on MySQL website but still could'nt installed it.

    So can anyone please explain me.

    Any help will be highly appreciated!
    hi my friend as you say you have worked with ms sql server 2005
    please help me to make connection with the same i m trying this for almost 2 days
    my code is
    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
    // Connection con = DriverManager.getConnection("jdbc:odbc:my");
    String connectionUrl = "jdbc:sqlserver://localhost" +
    "databaseName=emp" + "user=sa" + "password=password@123";
    // Connection con = DriverManager.getConnection("jdbc:odbc:my//localhost:5000" , "sa" , "password@123");
    Connection con = DriverManager.getConnection(connectionUrl);
    Statement stat = (Statement) con.createStatement();
    // String str = "select * from emp";
    ResultSet rs = stat.executeQuery("select * from emp");
    and my error is
    run:
    20 Sep, 2011 8:09:28 PM databasedemo.DataBaseDemo main
    SEVERE: null
    com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhostdatabaseName=empuser=sapassword=password@ 123, port 1433 has failed. Error: "null. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".
    at com.microsoft.sqlserver.jdbc.SQLServerException.ma keFromDriverError(SQLServerException.java:171)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.c onnectHelper(SQLServerConnection.java:1033)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.l ogin(SQLServerConnection.java:817)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.c onnect(SQLServerConnection.java:700)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.conne ct(SQLServerDriver.java:842)
    at java.sql.DriverManager.getConnection(DriverManager .java:582)
    at java.sql.DriverManager.getConnection(DriverManager .java:207)
    at databasedemo.DataBaseDemo.main(DataBaseDemo.java:3 6)
    BUILD SUCCESSFUL (total time: 15 seconds)
    i have enabled the tcp ip in the configuration tool and set the tcp port to 1433 under ip address tab
    please tell me what else i can do or where i m going wrong please i wanted to complete my jdbc project till tommorow

Similar Threads

  1. connection my mysql in jsp in myeclipse
    By pranjul137 in forum New To Java
    Replies: 12
    Last Post: 02-03-2014, 02:43 PM
  2. connection my mysql
    By pranjul137 in forum New To Java
    Replies: 5
    Last Post: 04-06-2010, 08:26 PM
  3. TWO IPs FOR MY MYSQL CONNECTION
    By tugalsan in forum JDBC
    Replies: 2
    Last Post: 03-21-2010, 08:46 PM
  4. Java-mysql connection
    By Kligham in forum New To Java
    Replies: 16
    Last Post: 11-25-2009, 01:28 PM
  5. no mysql connection
    By scchia in forum New To Java
    Replies: 12
    Last Post: 07-19-2008, 07:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •