Discussions

Web tier: servlets, JSP, Web frameworks: JDBC setup in TOMCAT 7

  1. JDBC setup in TOMCAT 7 (1 messages)

    I 'm  using to connect to the database (SQL 2005) from the jsp page this function from my SQLClass:

    public static String ReturnManufacture(String cr,long id_pr){
     
    Connection st_conn = null;
    Statement  st_stmt = null;
    int i = 1;

    String connURL = "jdbc:sqlserver://192.123.11.24:1433;databaseName=kkk2005;username=xxxxx;password=yyyyy";
               String Manufacture = "<tr BGCOLOR='#969696'><td>CompanyName</td><td>ManufacturePN</td></tr>";
                
               if ("".equals(cr))   
               return Manufacture;  
                       else  
    try{
          
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                st_conn = DriverManager.getConnection  (connURL);
                
                // Get a statement
                st_stmt = st_conn.createStatement(
                        ResultSet.TYPE_SCROLL_INSENSITIVE,
                        ResultSet.CONCUR_UPDATABLE
                        );
                // Query
                 
                String SQL = "select Description, MfrPartNumber from Manufacture where id ='" +  id_pr +  "' and POS ='" + cr + "' ";  
                ResultSet rs = st_stmt.executeQuery(SQL);
                
                try {
                      
                     while(rs.next())
                     {
                       Manufacture =  Manufacture + "<tr BGCOLOR='#efefef'><td width='35%'><h6><input  id=mn" + i + " type='text' value='" + rs.getString("Description").toString() + "' readonly='readonly' ></h6></td><td width='65%'>" +  
                                                                "<h6><input  id=mpn" + i + " type='text' value='" + rs.getString("MfrPartNumber").toString() + "' readonly='readonly' ></h6>" +  
                                                                "<input  type='button' name='Select' value='D'  onclick='Woo(" + i + ");' />" +  
                                                                "<input  type='button' name='Select' value='R'  onclick='Woo1(" + i + ");' /></td></tr>";              
                       i = i + 1;
                     }
                }catch(Exception e1) {}
     
            
            }
         
         catch(Exception e8) {
               }
    finally {
        try {
                if(st_stmt != null) st_stmt.close();
                st_stmt = null;
                if(st_conn != null) st_conn.close();
                st_conn = null;
            } catch (Exception e) {
                // Do nothing
            }
     
    }
    eend:
    return Manufacture;
    }

    I setup the classpath for jdbc driver :

    CLASSPATH =.;C:\Program Files\Microsoft SQL Server JDBC Driver\sqljdbc_3.0\enu\sqljdbc4.jar 

    and it can't connect to the database I received in the log file errorcode:9.

    With JDBC-ODBC driver is working.

    Any suggestions?

    Threaded Messages (1)

  2. MR . John[ Go to top ]

    This is wrong:

    st_stmt = st_conn.createStatement(
                        ResultSet.TYPE_SCROLL_INSENSITIVE,
                        ResultSet.CONCUR_UPDATABLE
                        );

     JDBC driver  it's not accepting createStatement function with parameters as JDBC-ODBC

    so this will  be :

    st_stmt = st_conn.createStatement();

    and it's working.