Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: how to configure sqlserver jdbc driver type 4

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to configure sqlserver jdbc driver type 4

    hi friends i am Banji. Please i need the steps on how am going to configure my microsoft sql server 2012 jdbc type 4.
    I downloaded sqljdbc from microsoft which contains two jar file sqljdbc and sqljdbc4 i don't know what to do next because i have never worked with this driver before. I will really appreciate it if anyone can solve my problem.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: how to configure sqlserver jdbc driver type 4

    Thread moved.

  3. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to configure sqlserver jdbc driver type 4

    Please i really need help on how to install and configure sql server 2012 jdbc driver i have set my enviromental variables, i even set the classpath in the command prompt like this set CLASSPATH =.;C:\Users\T-BAM\Desktop\sqljdbc_4.0\enu\sqljdbc4.jar i tried to unzip it into my Program Files its giving an error message like could not create C:\Program Files\Microsoft SQL Server JDBC Driver\sqljdbc_4.0 - unzip operation cancelled i eventually created a folder in program files Microsoft SQL Server JDBC Driver and set the classpath like this set CLASSPATH =.; C:\Program Files\Microsoft SQL Server JDBC Driver\sqljdbc_4.0\enu\sqljdbc4.jar still not working or is anything wrong with my simple code which goes like this

    Please i really need help on how to install and configure sql server 2012 jdbc driver i have set my enviromental variables, i even set the classpath in the command prompt like this set CLASSPATH =.;C:\Users\T-BAM\Desktop\sqljdbc_4.0\enu\sqljdbc4.jar i tried to unzip it into my Program Files its giving an error message like could not create C:\Program Files\Microsoft SQL Server JDBC Driver\sqljdbc_4.0 - unzip operation cancelled i eventually created a folder in program files Microsoft SQL Server JDBC Driver and set the classpath like this set CLASSPATH =.; C:\Program Files\Microsoft SQL Server JDBC Driver\sqljdbc_4.0\enu\sqljdbc4.jar still not working or is anything wrong with my simple code which goes like this

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

    try
    {
    String str = "select * from dbo.Patient_registration";
    String connectionUrl = "jdbc:sqlserver://T-BAM-PC:1433;databaseName=GeneralHospital;user=sa;passw ord=godhelpme";
    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
    Connection con = DriverManager.getConnection(connectionUrl);

    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(str);
    System.out.println();

    while (rs.next())
    {
    int id = rs.getInt(1);
    String surtname = rs.getString(2);
    String firstname = rs.getString(3);
    String midlename = rs.getString(4);
    String regdate = rs.getString(5);
    String collectiondate = rs.getString(6);
    String report =rs.getString(7);
    String age = rs.getString(8);
    String sex = rs.getString(9);


    System.out.println(id +"\t" + surtname + "\t" + firstname +"\t" + midlename +"\t" + regdate + "\t" + collectiondate + "\t" + report + "\t" + age + "\t" + sex );
    }


    }
    catch(Exception ex)
    {
    System.out.println("Error occured");
    System.out.println("Error:"+ex);


    }// TODO add your handling code here:
    }

    after clicking the jButton1 it throws an exception : Error occured
    Error:java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    I have read various articles to help my self still not working, I will so much appreciate it if anyone can help me solve this problem that is giving me sleepless night

    after clicking the jButton1 it throws an exception : Error occured
    Error:java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    I have read various articles to help my self still not working, I will so much appreciate it if anyone can help me solve this problem that is giving me sleepless night
    Last edited by olabanjitajudeen; May 19th, 2014 at 11:08 AM.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: how to configure sqlserver jdbc driver type 4

    Thread moved from 'What's wrong with my code'. Please see Announcements - JDBC & Databases for forum guidelines, and please wrap all code in the code tags

    Error:java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    The JVM cannot find that class - did you place the database driver on the classpath?

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: how to configure sqlserver jdbc driver type 4

    Please don't post duplicate topics, and post your code correctly.

    Threads merged.

  6. #6
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: how to configure sqlserver jdbc driver type 4

    Cross-post: how to install and configure sqlserver jdbc driver type 4

    Please wrap your code with [code] tags so that it is easier to read, e.g.,
    [code=java]
    // your code here
    [/code]

    It preserves formatting and provides syntax highlighting, e.g.,
    // your code here

    It will also help if you learn to use the fullstop or period character (.) correctly in order to properly punctuate your writing.

    As copeg already replied, "java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver" indicates the JRE is unable to find the SQLServerDriver class. The most likely reason is your class path setting and/or the location in which the JDBC driver is extracted.

    It'll be useful if you can first go through the following articles:

    With regards to sqljdbc.jar and sqljdbc4.jar, you can very easily find out the correct one to use by searching the Internet using the search term "sqljdbc sqljdbc4 difference." Example search result: Microsoft SQL Server JDBC Driver: Differences between sqljdbc.jar and sqljdbc4.jar?

    The MSDN forum page contains a link to an MSDN article, Using the JDBC Driver. The article contains a section specifically on setting the classpath, including the following note:
    On Windows systems, directory names longer than 8.3 or folder names with spaces may cause problems with classpaths. If you suspect these types of issues, you should temporarily move the sqljdbc.jar file or the sqljdbc4.jar file into a simple directory name such as C:\Temp, change the classpath, and determine whether that addresses the problem.
    Try the suggestion mentioned above by placing a copy of the jar file to C:\Temp, and adjust your classpath setting accordingly.

    You previously wrote,
    Quote Originally Posted by olabanjitajudeen View Post
    i tried to unzip it into my Program Files its giving an error message like could not create C:\Program Files\Microsoft SQL Server JDBC Driver\sqljdbc_4.0 - unzip operation cancelled i eventually created a folder in program files Microsoft SQL Server JDBC Driver and set the classpath like this set CLASSPATH =.; C:\Program Files\Microsoft SQL Server JDBC Driver\sqljdbc_4.0\enu\sqljdbc4.jar still not working
    You said you had trouble unzipping the driver, after which you manually created the folder and set the class path. Did you eventually managed to extract the jar file into the folder?

    Finally, note also that you can start your program via command line using the "java" command, and provide it with the -cp or -classpath argument along with the path to the folder location where the driver jar file is located. This is explained in the earlier 2 articles I provided above. Enclose the path with double-quotes to take care of spaces in folder names.

  7. #7
    Junior Member
    Join Date
    Aug 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to configure sqlserver jdbc driver type 4

    yes

Similar Threads

  1. Equivalent type of OracleTypes.CURSOR in sqlserver 2012
    By shijo in forum JDBC & Databases
    Replies: 0
    Last Post: February 27th, 2013, 09:15 AM
  2. type-4 driver with jdbc
    By muzammil786 in forum JDBC & Databases
    Replies: 3
    Last Post: February 13th, 2013, 08:04 AM
  3. type-4 driver with jdbc
    By muzammil786 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 12th, 2013, 12:00 PM
  4. JDBC Problem - com.mysql.jdbc.Driver
    By icu222much in forum Java Servlet
    Replies: 2
    Last Post: November 21st, 2011, 11:54 PM
  5. setting JDBC driver steps
    By planmaster in forum JDBC & Databases
    Replies: 1
    Last Post: November 6th, 2010, 02:02 PM