Problem with JDBC

Discussion in 'Java' started by il912, Oct 16, 2009.

  1. il912

    il912 New Member

    Joined:
    Oct 16, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I'm getting an weird error while accessing the database from JDBC driver in JSP using JAVA codes.

    plz help me to find a sollution the program and error details are below.

    Code:
    <%@ page import="java.sql.*" %>
    <%!
        Statement st;
        Connection con;
    %>
    <%  
        try{
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        con = DriverManager.getConnection("jdbc:odbc:DSN");
        
        st = con.createStatement();
        ResultSet res = st.executeQuery("SELECT * FROM tbNameOne");
        while(res.next())
        {
            out.println(res.getString(1) + "  " + res.getString(2) +"<br>");
        }
        }
        catch(Exception e)
        {
            out.print(e.toString());
        }
    %>
    these codes returns no error while building the project in NetBeans v6.1

    running this file returns me a error message, given below
    In the ODBC Data Source, i have added the DSN correctly in both the tabs (user DSN and system DSN, in case i was added in the wrong tab, to be on the safe side i added on both of them).

    I am Using:
    OS: Windows 7 RC
    Database: Microsoft SQL Server 2000
    IDE: NetBeans v6.1 (Server Apache TomCat)
     
  2. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    769
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    http://techiethakkar.blogspot.com
    Don't you need to open the connection?
     
  3. il912

    il912 New Member

    Joined:
    Oct 16, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    the connection will be establish by jdbc, using given below code
    Code:
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        con = DriverManager.getConnection("jdbc:odbc:DSN");
     
  4. satyedra pal

    satyedra pal New Member

    Joined:
    Mar 26, 2010
    Messages:
    93
    Likes Received:
    1
    Trophy Points:
    0
    Problem is related to database connection.So check your connectivity as database setting .And you are using DSN keyword so rename it Perhaps you could solve your problem.
     
  5. omid128

    omid128 New Member

    Joined:
    Jul 9, 2010
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    if you want to use JDBC I suggest you to use JDBC class from shine enterprise pattern

    it help you to set , the setting , it do all jobs for you

    it's easier and faster than that old jdbc.
    it has also soppurt hibernate

    here is the library and document :
    j2os.org
    http://SourceForge.net/projects/shine-enterpris/files/
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice