Results 1 to 17 of 17
  1. #1
    Ashu is offline Member
    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0

    Question How to connect to the database in eclipse if we are using sql server 2005 ?

    can any one tell how we can connect to SQL server 2005 if we are using eclipse and tomcat 7. Which and where the drivers do i need to install because it gives an error message always that driver not found.

    I have used driver sqljdbc 2.0,3.0,4.0 and pasted the jar file in tomcat 7 lib folder but still the error remains same. Do i need to set any other path to run if i am using eclipse.

    Thank you in advance please reply as soon as possible.

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

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    How are you connecting to the database in your code?
    That effects where the jar files need to go.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,718
    Rep Power
    5

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    might also be that the JDBC url is just wrong.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    Ashu is offline Member
    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    This is the code...

    Connection conn=null;
    Statement st=null;
    try {
    Class.forName("com.microsoft.jdbc.sqlserver.SQLSer verDriver");
    } catch (ClassNotFoundException e) {
    out.println("<h1>Driver not found:" + e + e.getMessage() + "</h1>" );
    }
    try {
    conn = DriverManager.getConnection (
    "jdbc:sqlserver://localhost:1433;DatabaseName=students",
    "sa", "ashu@123" );

    st = conn.createStatement();
    ResultSet rs;

    rs = st.executeQuery("SELECT * FROM students");
    while ( rs.next() ) {
    String name = (rs.getString("name"));
    String branch = (rs.getString("branch"));
    String id = (rs.getString("id"));

    out.println("<br>");
    }


    conn.close();
    } catch (Exception e) {
    out.println( "<h1>exception: "+e+e.getMessage()+"</h1>" );
    }

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

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    Well, then it needs to be in the WEB-INF/lib directory of your deployed application.

    Can I suggest for your exception handling that you use either a proper logging framework (this is preferable) or, at the least, use 'e.printStackTrace()' so you do not lose important exception informatrion. And if you still get an exception then post the full text, including stack trace.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Ashu is offline Member
    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    thnks 4 the suggestion i'll put this... but pls just tell me that there is no lib folder in web-inf .. soo...

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

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    Then you need to add one.
    Eclipse may or may not do this for you automatically.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    Ashu is offline Member
    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    I put the Jar file in the web\lib still the same prob its not working do i need to change anythng in tomcat aur in eclipse... any class varible or anythng...

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

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    And where's the exception including stack trace?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,718
    Rep Power
    5

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    yeah but you're building the connection from within your application, so your application needs access to the driver. Put the jar in WEB-INF/lib and not in tomcat/lib. You put it in tomcat/lib when you use a tomcat datasource, because then it is the server that makes the connection for you.

    Note: WEB-INF, not web-inf

    EDIT: Might also be that the driver package is actually wrong, if I have to believe this document the class is actually com.microsoft.sqlserver.jdbc.SQLServerDriver and not the com.microsoft.jdbc.sqlserver.SQLServerDriver you're using now.

    http://msdn.microsoft.com/en-us/library/ms378526.aspx

    That might depend on the version of the driver of course, this is for SQLServer 2012. Easy to figure out: open up the driver jar in your favorite zip tool and see which package is correct.
    Last edited by gimbal2; 07-29-2013 at 12:42 PM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    Ashu is offline Member
    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    How to connect to the database in eclipse if we are using sql server 2005 ?-stack-trace.png

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

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    Is copy/paste really too hard?
    That's hard on the eyes...

    So, clearly the jar file is not being deployed to WEB-INF/lib.
    You need to figure out how to fix that, which will be either something to do with how you build your application, or how Eclipse deploys it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #13
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,718
    Rep Power
    5

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    Yeah or the jdbc url is wrong, OR the driver is wrong. I think this is a case of mismatching the driver with the JDBC url, as things have changed a little from older driver versions to newer ones. I believe that because of this bit in the original post:

    I have used driver sqljdbc 2.0,3.0,4.0
    Better create a clean ship; take only the LATEST JDBC driver, put it in the WEB-INF/lib and configure according to the latest documentation from Microsoft.

    Connecting to SQL Server with the JDBC Driver
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  14. #14
    Ashu is offline Member
    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    That problem is solved but new problem arises i.e
    exception: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'students'.Invalid object name 'students'.
    its not taking my databaseName

  15. #15
    Ashu is offline Member
    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    Thnaks a lot guys my prob is solved... :-)

  16. #16
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,718
    Rep Power
    5

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    but what was the cause of your earlier problem? Please specify so that future people that find this thread can repeat what you did.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  17. #17
    Ashu is offline Member
    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0

    Default Re: How to connect to the database in eclipse if we are using sql server 2005 ?

    The first proble was i was putting the driver jar in tomcat Lib folder but it should be in the WEB-INF/lib folder of your application.
    And secondly the url was wrong and jre 1.7 supports sqljdbc4 not sqljdbc..

Similar Threads

  1. Replies: 10
    Last Post: 02-23-2012, 11:51 AM
  2. Replies: 3
    Last Post: 12-13-2010, 01:42 PM
  3. Replies: 4
    Last Post: 09-07-2010, 06:51 AM
  4. Replies: 3
    Last Post: 03-28-2010, 06:55 AM
  5. Connect to SQL server 2005
    By comp in forum JDBC
    Replies: 1
    Last Post: 03-25-2009, 11:25 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
  •