🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: es.comp.lenguajes.java
5 messages
5 total messages Started by ivo Thu, 08 Mar 2007 19:10
Problema al hacer consulta en SQL Server
#771
Author: ivo
Date: Thu, 08 Mar 2007 19:10
71 lines
3388 bytes
Tengo el siguiente mensaje de error:

Aqui Error getting Result SQLException:[Microsoft][SQLServer 2000
Driver for JDBC][SQLServer]El nombre de objeto 'usuarios' no es
válido.
SQLState: 42S02
VendorError: 208


ESTOY ACCESANDO A UNA TABLA DE SQL SERVER, LA DB ES  "montero", LA
TABLE ES "usuarios", Y EL HOST ES "IVANPIMA", Y QUIERO RECUPERAR LA
INFORMACION DE ESA TABLA, MIS DECLARACIONES SON LAS SIGUIENTES

private Connection createConn (String db){
try{DriverManager.registerDriver(new
com.microsoft.jdbc.sqlserver.SQLServerDriver());
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://
IVANPIMA:1433",user,pass);
     }catch (SQLException ex){
// handle any errors
            System.out.println("Error getting Connection SQLException:
" + ex.getMessage());
            System.out.println("SQLState: " + ex.getSQLState());
            System.out.println("VendorError: " + ex.getErrorCode());
            }catch (Exception er){
            	System.out.println(er.getMessage());
            }
        return conn;
}


    public ResultSet getData(String db, String sql){
        try{
            if (conn==null)
            conn = createConn(db);
            if(conn!=null){
                stmt = conn.createStatement();
                rs =
stmt.executeQuery(sql);
            }else{
                rs = null;
            }
        }catch(SQLException e){
            System.out.println("Aqui Error getting Result
SQLException: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("VendorError: " +
e.getErrorCode());
        }catch(Exception er){
        	System.out.println(er.getMessage());
        }
       return rs;
    }

Y DESDE AQUI LO MANDO LLAMAR

public String validarLogin(String usuar, String passw){
String query = "";
String nivelr = "";
query = "select usuario,pass,nivel from usuarios where usuario =
'"+usuar+"' and pass = '"+passw+"'";
System.out.println(query);
ResultSet validars = null;
try{
   validars = conn.getData("montero",query);
   if (validars.next()){
      nivelr = validars.getString(3);
     }
}catch (Exception er){System.out.println(er.getMessage());
 }return nivelr;
}
Re: Problema al hacer consulta en SQL Server
#773
Author: Fenix
Date: Fri, 09 Mar 2007 08:13
12 lines
1500 bytes
"ivo" <ivanpima@gmail.com> escribi� el
news:1173381009.006453.82580@j27g2000cwj.googlegroups.com: 

> query = "select usuario,pass,nivel from usuarios where usuario
> '"+usuar+"' and pass = '"+passw+"'";

    	Cuando compruebas en el WHERE usuario, no le pones ning�n operador. 
Ni igual ni LIKE.

    	Para errores de ese tipo, siempre es weno sacar la consulta que creas 
en c�digo, y ejecutarla en alg�n cliente para ver si es realmente lo que 
queremos.
Re: Problema al hacer consulta en SQL Server
#776
Author: jc7o
Date: Fri, 09 Mar 2007 20:16
87 lines
4277 bytes
Puede ser que el nombre del usuario, digamos josé, con el que te
conectas no sea el owner de la tabla "usuarios" entonces si haces
SELECT * FROM usuarios
el intentará hacer el select sobre la tabla jose.usuarios y no la
encontrará porque jose no tiene una tabla llamada usuarios
Intenta poniendo anteponiendo el owner de la tabla en la consulta, por
ejemplo
SELCT * FROM dbo.usuarios
Otra cosa a verificar es que el usuario tenga permisos de lectura
sobre esa tabla.

Saludos,

Julio.-

On 8 mar, 16:10, "ivo" <ivanp...@gmail.com> wrote:
> Tengo el siguiente mensaje de error:
>
> Aqui Error getting Result SQLException:[Microsoft][SQLServer 2000
> Driver for JDBC][SQLServer]El nombre de objeto 'usuarios' no es
> válido.
> SQLState: 42S02
> VendorError: 208
>
> ESTOY ACCESANDO A UNA TABLA DE SQL SERVER, LA DB ES  "montero", LA
> TABLE ES "usuarios", Y EL HOST ES "IVANPIMA", Y QUIERO RECUPERAR LA
> INFORMACION DE ESA TABLA, MIS DECLARACIONES SON LAS SIGUIENTES
>
> private Connection createConn (String db){
> try{DriverManager.registerDriver(new
> com.microsoft.jdbc.sqlserver.SQLServerDriver());
> conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://
> IVANPIMA:1433",user,pass);
>      }catch (SQLException ex){
> // handle any errors
>             System.out.println("Error getting Connection SQLException:
> " + ex.getMessage());
>             System.out.println("SQLState: " + ex.getSQLState());
>             System.out.println("VendorError: " + ex.getErrorCode());
>             }catch (Exception er){
>                 System.out.println(er.getMessage());
>             }
>         return conn;
>
> }
>
>     public ResultSet getData(String db, String sql){
>         try{
>             if (conn==null)
>             conn = createConn(db);
>             if(conn!=null){
>                 stmt = conn.createStatement();
>                 rs =
> stmt.executeQuery(sql);
>             }else{
>                 rs = null;
>             }
>         }catch(SQLException e){
>             System.out.println("Aqui Error getting Result
> SQLException: " + e.getMessage());
>             System.out.println("SQLState: " + e.getSQLState());
>             System.out.println("VendorError: " +
> e.getErrorCode());
>         }catch(Exception er){
>                 System.out.println(er.getMessage());
>         }
>        return rs;
>     }
>
> Y DESDE AQUI LO MANDO LLAMAR
>
> public String validarLogin(String usuar, String passw){
> String query = "";
> String nivelr = "";
> query = "select usuario,pass,nivel from usuarios where usuario =
> '"+usuar+"' and pass = '"+passw+"'";
> System.out.println(query);
> ResultSet validars = null;
> try{
>    validars = conn.getData("montero",query);
>    if (validars.next()){
>       nivelr = validars.getString(3);
>      }
>
> }catch (Exception er){System.out.println(er.getMessage());
>  }return nivelr;
> }
Re: Problema al hacer consulta en SQL Server
#777
Author: ivo
Date: Mon, 12 Mar 2007 17:12
18 lines
1851 bytes
La instruccion

> > query = "select usuario,pass,nivel from usuarios where usuario =
> > '"+usuar+"' and pass = '"+passw+"'";

es correcta solo por el formato del correo se dividio.

En el caso del Query le he agregado el owner y quedo de la siguiente
manera:

"select usuario,pass,nivel from usuarios where montero.usuario =
'"+usuar+"' and pass = '"+passw+"'";

y aun asi marca el mismo error, he comprobado el usuario, porque he
conectado con el driver de un JDBC-ODBC y si funciona bien, pero
quiero hacerlo directamente sobre la conexion de SQL Server.

Gracias por sus respuestas.
Re: Problema al hacer consulta en SQL Server
#778
Author: Guevonaso
Date: Tue, 13 Mar 2007 07:50
16 lines
1882 bytes
On 12 mar, 18:12, "ivo" <ivanp...@gmail.com> wrote:
[...] he comprobado el usuario, porque he
> conectado con el driver de un JDBC-ODBC y si funciona bien, pero
> quiero hacerlo directamente sobre la conexion de SQL Server.
>
>[...]

Prueba la conexion indicando la base de datos:

jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs

es posible que simplemente esté usando una base de datos diferente de
la que tu quieres.
Es lo que se me ocurre .

Saludos.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads