com.microsoft.sqlserver.jdbc.SQLServerStatement cannot be cast to java.sql.Connection
Publicado por oscarjim_007 (4 intervenciones) el 12/08/2016 18:11:02
Buen dia, tengo un problema con mi metodo al intentar generar un reporte y no he podidio solucionarlo, dejo la salida que me da cuando ejecuto el reporte y el metodo que lo hace, tambien mi calse conectora . de ante mano muchas gracias.
// esto es lo que sale cuando presiono mi boton de generar reporte
com.microsoft.sqlserver.jdbc.SQLServerStatement cannot be cast to java.sql.Connection
y este es el codigo en el evento del boton
esta es mi clase para conectarme a la bd
// esto es lo que sale cuando presiono mi boton de generar reporte
com.microsoft.sqlserver.jdbc.SQLServerStatement cannot be cast to java.sql.Connection
y este es el codigo en el evento del boton
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
private void JBREPORTEActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String path = "";
try{
path = getClass().getResource("/REPORTES/PRESOC.jasper").getPath();
path = URLDecoder.decode(path, "UTF-8");
Connection cn = (Connection) new CONEXIONBD().CONEXIONBD(); creo que el problema radica en esta linea
Map parametro = new HashMap();
JasperReport jr = (JasperReport) JRLoader.loadObject(path);
JasperPrint imp = JasperFillManager.fillReport(jr,parametro,cn);
JasperViewer vista = new JasperViewer(imp, false);
vista.setTitle("Reporte Presocios en Formacion");
vista.setVisible(true);
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
esta es mi clase para conectarme a la bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package CONEXION;
import java.sql.*;
import javax.swing.JOptionPane;
public class CONEXIONBD {
String url="jdbc:sqlserver://localhost:1433;databaseName=cuautitlan";
String user="infiwin";
String pass="infiwin";
public Connection conexion = null;
public Statement sta = null;
public Statement CONEXIONBD(){
try{
conexion = DriverManager.getConnection(url,user,pass);
sta=conexion.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
}
catch(SQLException i){
JOptionPane.showMessageDialog(null, i);
}
return sta;
}
}
Valora esta pregunta


0