Database connection problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • doniravi
    New Member
    • Jan 2007
    • 12

    Database connection problem

    i placed every thing in proper place(i.e in lib folder ) and placed in class path also...

    but still i am facing problem is that when i run my application i am unable to get any response......t hat is in browser i didnt notice anything.....


    my code is:

    i have database called ravi and one table named kumar.

    <%
    try
    {
    Class.forName(" com.microsoft.s qlserver.jdbc.S QLServerDriver" );
    String url="jdbc:micro soft:sqlserver://localhost:1433, ravi";
    Connection con=DriverManag er.getConnectio n
    ("url","sa","sa ");
    out.println("co nnected");
    Statement st=con.createSt atement();
    ResultSet re=sql.executeQ uery("select * from stuinfo");
    String sql ="INSERT INTO kumar VALUES('Michael ','dba','9000') ";
    con.close();
    }
    catch (Exception e)
    {
    e.printStackTra ce();
    }
    }


    i m not getting the stmt written in out.println();

    i think the problem is occuring at connection statement.....

    the jar files i mentioned in lib folder are sqljdbc.jar,odb d14.jar,jtdc-1.2.jarmsutil.j ar,msbase.jar,m ssqlserver.jar, classes111.jar

    i put these in class path also....

    tell me where am i doing wrong?

    is any intermediate cinnector is required like in the case of my sql?

    thanks in advance

    ragards
    ravi......
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    This is not a Coldfusion problem. I'll redirect you to the Java forum.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by doniravi
      i placed every thing in proper place(i.e in lib folder ) and placed in class path also...



      but still i am facing problem is that when i run my application i am unable to get any response......t hat is in browser i didnt notice anything.....





      my code is:



      i have database called ravi and one table named kumar.



      <%

      try

      {

      Class.forName(\ "com.microsoft. sqlserver.jdbc. SQLServerDriver \");

      String url=\"jdbc:micr osoft:sqlserver ://localhost:1433, ravi\";

      Connection con=DriverManag er.getConnectio n

      (\"url\",\"sa\" ,\"sa\");

      out.println(\"c onnected\");

      Statement st=con.createSt atement();

      ResultSet re=sql.executeQ uery(\"select * from stuinfo\");

      String sql =\"INSERT INTO kumar VALUES(\'Michae l\',\'dba\',\'9 000\')\";

      con.close();

      }

      catch (Exception e)

      {

      e.printStackTra ce();

      }

      }





      i m not getting the stmt written in out.println();



      i think the problem is occuring at connection statement.....



      the jar files i mentioned in lib folder are sqljdbc.jar,odb d14.jar,jtdc-1.2.jarmsutil.j ar,msbase.jar,m ssqlserver.jar, classes111.jar



      i put these in class path also....



      tell me where am i doing wrong?



      is any intermediate cinnector is required like in the case of my sql?



      thanks in advance



      ragards

      ravi......


      Now doni, multi posting is not a very good thing to do in these forums. I appreciate that you have had this problem for a long time now and also feel bad that we have not been able to help you out yet but just keep posting for this problem in the same thread in this forum.



      You said there is nothing shown on the browser, are there any exceptions being thrown?

      Comment

      • abctech
        New Member
        • Dec 2006
        • 157

        #4
        Originally posted by doniravi
        i placed every thing in proper place(i.e in lib folder ) and placed in class path also...

        but still i am facing problem is that when i run my application i am unable to get any response......t hat is in browser i didnt notice anything.....


        my code is:

        i have database called ravi and one table named kumar.

        <%
        try
        {
        Class.forName(" com.microsoft.s qlserver.jdbc.S QLServerDriver" );
        String url="jdbc:micro soft:sqlserver://localhost:1433, ravi";
        Connection con=DriverManag er.getConnectio n
        ("url","sa","sa ");
        out.println("co nnected");
        Statement st=con.createSt atement();
        ResultSet re=sql.executeQ uery("select * from stuinfo");
        String sql ="INSERT INTO kumar VALUES('Michael ','dba','9000') ";
        con.close();
        }
        catch (Exception e)
        {
        e.printStackTra ce();
        }
        }


        i m not getting the stmt written in out.println();

        i think the problem is occuring at connection statement.....

        the jar files i mentioned in lib folder are sqljdbc.jar,odb d14.jar,jtdc-1.2.jarmsutil.j ar,msbase.jar,m ssqlserver.jar, classes111.jar

        i put these in class path also....

        tell me where am i doing wrong?

        is any intermediate cinnector is required like in the case of my sql?

        thanks in advance

        ragards
        ravi......
        Hi doniravi,

        I am not sure if this can help you but try declaring the Connection object in the declarative tag instead of the scriptlet and register your driver and get the connection in jspInt() and close it in jspDestroy()

        I am working with MySql and Type1 driver so I would normally do as foll:-

        Code:
        <%!
            Connection con;
        			
            public void jspInit()
            {
             try
             {
              DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
              con = DriverManager.getConnection("jdbc:odbc:<your dsn name>"); 				
             }		
             catch(Exception e)
             {
             System.out.println(e);				
             }	
            }
        
            public void jspDestroy() 
            {
             try
             {
              con.close();
             }
             catch(Exception e)
            {
              System.out.println(e);	
            }
           }
        
         %>
         <%
           //then creating the Statement,ResultSet, executing the query etc I do in the scriptlet
        
         %>
        See if doing the above helps you in any way..and if it doesn't then do post your exceptions, maybe someone can help you after having a look at them!

        By the way a simple thing I would like to share--
        If you arent a pro and you really wanna know which part of your program is giving error put SOP's at regular intervals so that way based on the SOP's that've printed on the server's console you can get a rough idea about where your code is stuck!!

        This is what works for me(Most Times, Not All !!).Maybe doesn't get the problem solved but atleast I know uptill where my code is actually working ..and which part is giving the problem..then accordingly you can work on the erroneous code!Later you can just remove the SOP's once your code is fully up and running!

        Cheers

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Someone with more knowledge of java than me will have to confirm this but is this really right

          Code:
          String url="jdbc:microsoft:sqlserver://localhost:1433,ravi";
          Connection con=DriverManager.getConnection("url","sa","sa");
          shouldn't it be

          Code:
          String url="jdbc:microsoft:sqlserver://localhost:1433,ravi";
          Connection con=DriverManager.getConnection(url,"sa","sa");
          otherwise you are using the string "url" rather than the string contained in the variable url.



          P.S. I would just like to re-itterate what r035198x has already said about NOT double posting.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by Banfa
            Someone with more knowledge of java than me will have to confirm this but is this really right



            Code:
            String url=\"jdbc:microsoft:sqlserver://localhost:1433,ravi\";
            
            Connection con=DriverManager.getConnection(\"url\",\"sa\",\"sa\");


            shouldn\'t it be



            Code:
            String url=\"jdbc:microsoft:sqlserver://localhost:1433,ravi\";
            
            Connection con=DriverManager.getConnection(url,\"sa\",\"sa\");


            otherwise you are using the string \"url\" rather than the string contained in the variable url.







            P.S. I would just like to re-itterate what r035198x has already said about NOT double posting.


            You should pay us more frequent visits Banfa. That is probably the reason why the code is not working. The exception stack trace would confirm this but doni did not give it.

            Comment

            Working...