Results 1 to 6 of 6
  1. #1
    mxb7642 is offline Member
    Join Date
    Aug 2007
    Posts
    2
    Rep Power
    0

    Default connecting to a database

    this is probably a really stupid question, but this i my first time working with databases so here it goes. I'm trying to connect to a database using the following code:

    Java Code:
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    String url = "jdbc:sqlserver://localhost:1433;database=tempdb;";
    String user = "sa";
    String pw = "";
    Connection con = DriverManager.getConnection( url, user, pw );
    I keep getting this error however - Login failed for user 'sa'. Reason: Not associated with a trusted SQL Server connection..
    I've checked the database and this is deffinitely a valid username. I've also tried several other databases with various usernames and i keep getting the same error.

    Is there something horribly wrong with my code? Please help

  2. #2
    ksbrother is offline Member
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Default

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:dsname" ,"username","password");

  3. #3
    herfnai is offline Member
    Join Date
    Aug 2008
    Posts
    13
    Rep Power
    0

    Default

    hello you must make odbc and:
    Connection cn=null;
    Statement stm=null;
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    cn=DriverManager.getConnection("jdbcdbc:database name");
    stm=cn.createStatement(ResultSet.TYPE_SCROLL_SENSI TIVE,
    ResultSet.CONCUR_UPDATABLE);
    JOptionPane.showMessageDialog(null,"connected");

    }catch(Exception e)
    {JOptionPane.showMessageDialog(null,"eroor" +"\n"+e.getMessage());


    }

  4. #4
    Join Date
    Sep 2009
    Location
    Gurgoan
    Posts
    4
    Rep Power
    0

    Default

    when jsp with sqlserver2005 on netbeans on glassfish server then send a error message my page is not connected so tell me how can do this and also say how i configure tomcat6.0 with netbeans it also send error that not find catalina.bat and myclasspath.bat file

  5. #5
    Join Date
    Sep 2009
    Location
    Gurgoan
    Posts
    4
    Rep Power
    0

    Exclamation jsp with sqlserver on netbeans

    databsase is not doing well on my page and servlet page occured error
    like org.apache.jaspre......something

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Post the exact exact error message that got.
    Also realize that error messages are trying to give you clues as to what the problem may be.

Similar Threads

  1. Connecting to a database
    By peiceonly in forum New To Java
    Replies: 2
    Last Post: 04-06-2008, 03:28 PM
  2. problem in connecting to mysql database
    By nancyv in forum Java Servlet
    Replies: 6
    Last Post: 04-02-2008, 12:33 PM
  3. Replies: 0
    Last Post: 02-13-2008, 12:26 PM
  4. Error while connecting to a database
    By Fukushuusha in forum JDBC
    Replies: 2
    Last Post: 12-16-2007, 10:40 AM
  5. connecting to mysql database
    By javagal in forum NetBeans
    Replies: 2
    Last Post: 08-04-2007, 01:36 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
  •