Results 1 to 11 of 11
  1. #1
    sabra is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Talking Proble with connect

    import java.sql.*;

    public class JDBCConnectionExample {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    // Create a variable for the connection string.
    String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
    "databaseName=NovaBaza;integratedSecurity=false;us er=sa;password=javajdbc";

    // Declare the JDBC objects.
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;

    try {

    // Establish the connection.
    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
    con = DriverManager.getConnection(connectionUrl);

    // Create and execute an SQL statement that returns a
    // set of data and then display it.
    //String SQL = "SELECT * FROM BLOBTest;";
    //stmt = con.createStatement();
    //rs = stmt.executeQuery(SQL);
    //displayRow("Ident", rs);
    }

    // Handle any errors that may have occurred.
    catch (Exception e) {
    e.printStackTrace();
    }

    finally {
    if (rs != null) try { rs.close(); } catch(Exception e) {}
    if (stmt != null) try { stmt.close(); } catch(Exception e) {}
    if (con != null) try { con.close(); } catch(Exception e) {}
    }


    //private static void displayRow(String title, ResultSet rs) {
    try {
    /// System.out.println(title);
    // while (rs.next()) {
    // System.out.println(rs.getString());
    // }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }
    java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at JDBCConnectionExample.main(JDBCConnectionExample.j ava:22)

    !MS SQL Server 2005- please nedd help

  2. #2
    HerrK. is offline Member
    Join Date
    Jun 2010
    Location
    Berlin
    Posts
    22
    Rep Power
    0

    Default

    First of all, why have you put this into a new thread? You've started your post right here http://www.java-forums.org/database/...onnection.html and should go on there.

    Then I mentioned before, that if you want someone to help you, you should first invest some time and at least use the CODE tags to mark the code as such and format the code so it could be read more easy.

    And if you want help, than ask a question. No one will guess what
    Quote Originally Posted by sabra View Post
    !MS SQL Server 2005- please nedd help
    means. Is "!MS SQL Server" equal to "not MS SQL Server"? That you need help is obvious while you created a post, but where are some lines what you have done (and why) and what is not working correctly? It doesn't take too much time to put this into one or two sentences, does it?

    The error message "java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver" tries to tell you something, so what do you think might be the problem? (I am willing to help you, but you must be willing to keep the post more clean and maybe starting by doing some search, googling as well as inside the forum). If you don't find anyone with the same problem, just be so kind and mention what you've tried before.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    The JVM is telling you it can not find a class. Where is that class defined? Probably in a jar file. Find that jar file and add it to the classpath for the JVM.

  4. #4
    sabra is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Post Herrk!

    I need one simply programm connecting to sql database, please.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    Your program might work if you give it the libraries it needs.

  6. #6
    sabra is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Post Hi Norm!

    "Your program might work if you give it the libraries it needs."
    1. what libraries;
    2. whre I give?

    Will you help me please.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    The missing class file "java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    " is probably in a jar file(library). You need to find that jar file and put it on the classpath for the java program.

    Where did you get the program you're trying to execute? Ask the author of the program where to get the library.

  8. #8
    HerrK. is offline Member
    Join Date
    Jun 2010
    Location
    Berlin
    Posts
    22
    Rep Power
    0

    Default

    Have you ever simple googled "com.microsoft.sqlserver.jdbc.SQLServerDriver" ? My first result is a real good description by MS which explains how to connect to a MS SQL Server and includes sample code as well....

    PS.: If you google "jdbc driver mssql" (without the quotes!) you will get to the MS download page, where the corresponding .jar could be downloaded. The other side descripes how to include the driver into the CLASSPATH
    Last edited by HerrK.; 06-13-2010 at 06:01 PM.

  9. #9
    sabra is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Red face Hi Norm!

    Will you send me one simple programm code connecting to sql server 2005database, please.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    Sorry, I do not have any programs like that.
    You'd still need the library with the missing class file.

  11. #11
    sabra is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

Similar Threads

  1. Connect Four
    By chick in forum New To Java
    Replies: 3
    Last Post: 05-04-2010, 04:33 AM
  2. Connect 4
    By pansylea in forum New To Java
    Replies: 0
    Last Post: 12-11-2009, 03:36 PM
  3. Replies: 1
    Last Post: 05-11-2009, 01:13 PM
  4. how to connect with my GUI
    By doha786 in forum New To Java
    Replies: 2
    Last Post: 04-01-2009, 04:59 PM
  5. Proble displaying images dynamically in jsp
    By javaxprogrammer in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-09-2009, 08:13 AM

Posting Permissions

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