Repost: java.sql.SQLException with jdbc:odbc bridge driver and api

Discussion in 'Java' started by Kermit Piper, Jun 12, 2006.

  1. Kermit Piper

    Kermit Piper Guest

    Hello,

    I've seen a lot of information on this error: java.sql.SQLException:
    [Microsoft][ODBC Driver Manager] Data source name not found and no
    default driver specified.

    However, the only definitive solution I can find is going to Control
    Panel-->Administrative Tools-->Data Sources(OBDC)-->System DSN-->etc. I

    did this and the connection tests fine. So, this is not the cause of
    the error in this case. So, given what I have explained and the snippet

    below, can someone please offer some help in resolving this. I am
    running in the following environment: Windows XP Pro, SQL Server 2000,
    JBoss 4.0.2, JDK 150_07.

    1. created my database
    2. created a system DSN
    3. did the required modifications in it
    4. added the rt.jar to the web-inf\lib dir and did another build, then
    restarted JBoss.

    // JDBC:ODBC bridge using api and using table:

    This method is used in my LoginServlet:
    public String validateUser(String inputUserid, String inputPwd) throws
    SQLException
    {
    String returnString = null;
    String dbUserid = "testuser";
    String dbPassword = "password" ;
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch (ClassNotFoundException cnfe)
    {
    System.out.println(cnfe);
    }
    try
    {
    Connection con =
    DriverManager.getConnection("jdbc:eek:dbc:LocalServer",
    dbUserid ,dbPassword);
    Statement stmt = con.createStatement();
    String sql = "select USERID from USERTABLE where USERID

    = '" +
    inputUserid + "' and PASSWORD = '" + inputPwd +"' ;" ;
    ResultSet rs = stmt.executeQuery(sql);
    if (rs.next())
    {
    returnString = rs.getString("USERID");
    }
    stmt.close();
    con.close();
    }
    catch (SQLException sqle)
    {
    System.out.println(sqle);
    }
    return returnString ;
    }

    Any help would be greatly appreciated.
    Thanks,
    KP
     
    Kermit Piper, Jun 12, 2006
    #1
    1. Advertising

  2. Kermit Piper

    Chris Uppal Guest

    Kermit Piper wrote:

    > // JDBC:ODBC bridge using api and using table:


    You might have better luck using a real JDBC driver (not the flaky ODBC
    bridge). I believe that MS have their own driver, and there is jIDS too (I
    have never used either of them myself, but people have written good things
    about jTDS here).

    Oh, by the way, unless this was just demo code to illustrate the problem, you
    have a Very Nasty potential security hole here:

    > String sql = "select USERID from USERTABLE where USERID
    > = '" + inputUserid + "' and PASSWORD = '" + inputPwd +"' ;" ;


    Never, ever, ever, build SQL strings from user-supplied input. Use prepared
    statements.

    -- chris
     
    Chris Uppal, Jun 13, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Berboris
    Replies:
    0
    Views:
    917
    Berboris
    Jul 1, 2003
  2. Dave Glasser
    Replies:
    5
    Views:
    2,212
    Brett Sheeran
    Aug 27, 2003
  3. Dave Stallard
    Replies:
    4
    Views:
    3,157
    Michael Borgwardt
    Nov 12, 2004
  4. Kermit Piper
    Replies:
    0
    Views:
    722
    Kermit Piper
    Jun 11, 2006
  5. guptapr
    Replies:
    0
    Views:
    2,069
    guptapr
    Aug 28, 2009
Loading...

Share This Page