estos son los codigos:
JPS
<%@ page import="java.io.*,java.util.*,java.net.*,java.sql. *,imprimir.imprimir" %>
<%
if(request.getParameter("GRABAR") != null)
{
// objetos de enlace
Connection canal = null;
ResultSet tabla= null;
Statement instruccion=null;
// abriendo canal o enlace en su propio try-catch
try {
Class.forName("com.mysql.jdbc.Driver").newInstance ();
canal=DriverManager.getConnection("jdbc:mysql:///cablevision_atc", "root", "");
instruccion = canal.createStatement(ResultSet.TYPE_SCROLL_SENSIT IVE,
ResultSet.CONCUR_UPDATABLE);
} catch(java.lang.ClassNotFoundException e){} catch(SQLException e) {};
//cargando los campos a grabar
// excepto clave porque en mysql es de tipo auto-increment
int estado = 0;
String q="insert into ticket(estado_ticket) values(\"" +estado+"\"); ";
try {
// agregando renglon (insert)
int n=instruccion.executeUpdate(q);
//avisando que se hizo la instruccion
out.println("REGISTRO INSERTADO");
imprimir imprimir=new imprimir();
} catch(SQLException e) {out.println(e);};
try{
// tabla.close();
instruccion.close();
canal.close();
} catch(SQLException e) {out.println(e);};
};
// construyendo forma dinamica
out.println("<FORM ACTION=index.jsp METHOD=post>");
out.println("<INPUT TYPE=SUBMIT NAME=GRABAR VALUE=INSERTAR ><BR>");
out.println("</FORM>");
%>
Y ESTA ES MI CLASE
Código PHP:
package imprimir;
import java.sql.*;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;
/**
* Driver program to connect to a database and to view a jasper report (.jrxml)
* @author Oguzhan Topsakal
* @since 23 March 2006
*
* Required jar files to run this class:
* 1. jasperreports-1.2.0.jar
* 2. classes12.jar (for Oracle JDBC connection)
* 3. commons-beanutils-1.5.jar
* 4. commons-collections-2.1.jar
* 5. commons-digester-1.7.jar
* 6. commons-logging-1.0.2.jar
*
*/
public class imprimir {
/**
* Constructor for ReportDriver
*/
public imprimir() {
}
/**
* Takes 3 parameters: databaseName, userName, password
* and connects to the database.
* @param databaseName holds database name,
* @param userName holds user name
* @param password holds password to connect the database,
* @return Returns the JDBC connection to the database
*/
public static Connection connectDB(String databaseName, String userName, String password) {
Connection jdbcConnection = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance ();
jdbcConnection = DriverManager.getConnection("jdbc:mysql:///cablevision_atc", "root", "");
}catch(Exception ex) {
String connectMsg = "Could not connect to the database: " + ex.getMessage() + " " + ex.getLocalizedMessage();
System.out.println(connectMsg);
}
return jdbcConnection;
}
/**
* Takes 4 parameters: databaseName, userName, password, reportFileLocation
* and connects to the database and prepares and views the report.
* @param databaseName holds database name,
* @param userName holds user name
* @param password holds password to connect the database,
* @param reportFile holds the location of the Jasper Report file (.jrxml)
*/
public static void runReport(String databaseName, String userName, String password,String reportFile) {
try{
JasperDesign jasperDesign = JRXmlLoader.load(reportFile);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Connection jdbcConnection = connectDB(databaseName, userName, password);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, jdbcConnection);
JasperViewer.viewReport(jasperPrint);
//JasperPrintManager.printPages(jasperPrint,0,jasperPrint.getPages().size()-1,true);
}catch(Exception ex) {
String connectMsg = "Could not create the report " + ex.getMessage() + " " + ex.getLocalizedMessage();
System.out.println(connectMsg);
}
}
/**
* Uses runReport method to connect to the database and to prepare and view the report.
* @param args Takes 4 arguments as an input: databaseName, userName, password, reportFileLocation
* args[0] holds database name,
* args[1] holds user name
* args[2] holds password to connect the database,
* args[3] holds the location of the Jasper Report file (.jrxml)
*/
public static void main(String[] args) {
String databaseName = "cablevision_atc";
String userName = "root";
String password = "";
String reportFile = "C:\\wamp\\www\\Cablevision\\JAVA\\ticket.jrxml";
runReport(databaseName, userName, password, reportFile);
return;
} }
AMBOS FUNCIONAN POR SEPARADO