none
JDBC and NetBeans

    Question

  • Hello

    I am currently coding a server java code that has to connect to MySQL Server and do so stuff with a database, using:

    NetBeans 7.0.1 + JDK1.7
    MySQL Server 5.1

    I found many different pages all exposing different lines of code but none are working. First thing, I tried with different versions of J/Connectors that I imported to my library:

    mysql-connector-java-1.5.18-bin.jar
    sqljdbc.jar
    sqljdbc4.jar

    As for the code to connect, I also found different versions, but none are working without firing a ClassNotFoundException error:

    try{
    Class.forName("com.mysql.jdbc.driver");
    String connectionUrl = "jdbc:sqlserver://localhost:1433;"+
    "user=root;password=mypassword;";
    Connection con = DriverManager.getConnection(connectionUrl);

    } catch (SQLException e){
    //handles error

    } catch (ClassNotFoundException cE){

    //handles error

    }



    I also tried with:

    Class.forName("com.miscrosoft.sqlserver.jdbc.SQLServerDriver");

    I think that the problem comes from CLASSPATH but I don't know which value to set (mysql-connector-java-1.5.18-bin.jar is linked to my project but is not in java/lib folder of Program Files....)


    Can someone could provide me with some clarifications as I am really stuck now :(

    Thanks in advance!






    • Edited by Badoumba Friday, March 30, 2012 9:12 AM
    Friday, March 30, 2012 8:39 AM

Answers

  • Hello,

    I don't think that you are using SQL Server ( but Mysql ) and Visual Studio ( but NetBeans ).

    I would suggest you tthe forums for NetBeans where you should find more help even if you are using microsoft.sqlserver.jdbc.SQLServerDriver :

    http://netbeans.org/community/lists/index.html 

    Have a nice day

    PS : are you sure of the name of your class miscrosoft.sqlserver.jdbc.SQLServerDriver


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.


    Friday, March 30, 2012 2:15 PM
    Moderator
  • MySQL and Microsoft SQL-Server are two totally different products and a driver and connection string that will work with SQL-Server won't work at all with MySQL.

    The JDBC drivers sqljdbc.jar and sqljdbc4.jar are to be used exclusively for SQL-Server and won't work with MySQL and the address localhost:1433 is also an address specific for SQL-Server and won't work for MySQL because MySQL use a different port than 1433.

    If you have a problem connecting with MySQL from NetBeans, you should ask in a forum dedicated to either MySQL or NetBeans (this one is for SQL-Server, not for MySQL)  and also take care about not confusing MySQL with SQL-Server.

    Saturday, March 31, 2012 10:46 AM

All replies

  • Hello,

    I don't think that you are using SQL Server ( but Mysql ) and Visual Studio ( but NetBeans ).

    I would suggest you tthe forums for NetBeans where you should find more help even if you are using microsoft.sqlserver.jdbc.SQLServerDriver :

    http://netbeans.org/community/lists/index.html 

    Have a nice day

    PS : are you sure of the name of your class miscrosoft.sqlserver.jdbc.SQLServerDriver


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.


    Friday, March 30, 2012 2:15 PM
    Moderator
  • MySQL and Microsoft SQL-Server are two totally different products and a driver and connection string that will work with SQL-Server won't work at all with MySQL.

    The JDBC drivers sqljdbc.jar and sqljdbc4.jar are to be used exclusively for SQL-Server and won't work with MySQL and the address localhost:1433 is also an address specific for SQL-Server and won't work for MySQL because MySQL use a different port than 1433.

    If you have a problem connecting with MySQL from NetBeans, you should ask in a forum dedicated to either MySQL or NetBeans (this one is for SQL-Server, not for MySQL)  and also take care about not confusing MySQL with SQL-Server.

    Saturday, March 31, 2012 10:46 AM
  • ok. Thanks for your answers

    I move to NetBeans forum !

    Saturday, March 31, 2012 6:02 PM
  • Hello,

    Don't forget to mark the reply(ies) which have decided you to post on the NetBean Forums.It is one the simplest way to say thanks and it avoids to let a thread unanswered.

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    Saturday, March 31, 2012 6:09 PM
    Moderator