CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2003
    Location
    Athens, Greece
    Posts
    1,094

    JDBC and SQL server 2000

    I need to pack my application that uses an SQL server 2000 DB and move it to a user's computer. My code is:
    Code:
    // Connection string
        String conStr = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Video Club;User=VClub;Passwd=VClub";
    
        public void NewCustomer(String firstName,
                                String lastName,
                                String phone,
                                String address) {
            // SQL Query string
            String query = "EXEC prc_NewCustomer N'" + firstName +
                           "', N'" + lastName + "', N'" + phone +"', N'" + address + "'";
    
            try {
                // Load the JDBC driver
                Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
                Connection con = DriverManager.getConnection (conStr);
    
                // Get a connection
                Statement stmt = con.createStatement();
    
                // Execute query
                stmt.execute(query);
    
                con.close();
            }
            catch(ClassNotFoundException esql){
                esql.printStackTrace();
            }
            catch(SQLException esql){
                esql.printStackTrace();
            }
        }
    The problem with this code is that the user's computer should have sa with empty password. Is there a way to use Windows authentication? Or if not how should I add a user in SQL server wirh appropriate rights so that my application may use this login to connect?
    Extreme situations require extreme measures

  2. #2
    Join Date
    Sep 2004
    Posts
    247

    Re: JDBC and SQL server 2000

    I don't think you can use Windows authentication for JDBC to SQL Server, you have to use SQL Server authentication. See http://support.microsoft.com/default...b;en-us;313100

    You will need to use TSQL to create users on your users SQL Server if they do not already exist.

  3. #3
    Join Date
    Apr 2003
    Location
    Athens, Greece
    Posts
    1,094

    Re: JDBC and SQL server 2000

    Thank you very much.
    One SQL server related question: Can I create the user on that specific DB so that after backup(on my computer)-restore(on the user's computer) I would not have to create the user again?
    Also do I have to grant exec access to my stored procedures only or is it smthng more that I need?
    I have tried to create a user but I could not connect that's why I am asking...
    Extreme situations require extreme measures

  4. #4
    Join Date
    Sep 2004
    Posts
    247

    Re: JDBC and SQL server 2000

    I'm not sure if users are sored in a backup (I would imagine so however). When ever I transfer a database, I usually end up creating a login with the command sp_addlogin (see http://msdn.microsoft.com/library/de..._adda_0q7i.asp)

  5. #5
    Join Date
    Apr 2003
    Location
    Athens, Greece
    Posts
    1,094

    Re: JDBC and SQL server 2000

    Thanx again. If I don't manage to put it in the backup, I'll do it in a batch using sp_addlogin.
    Extreme situations require extreme measures

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured