I have a big problem, y need to print a jasper report, but it must to be with jsp. this is my jsp
please help me - <%@ 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_SENSITIVE,
-
-
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 print = 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("NOMBRE :<INPUT TYPE=TEXT NAME=NOMBRE><BR>");
-
-
//out.println("EDAD :<INPUT TYPE=TEXT NAME=EDAD><BR>");
-
-
//out.println("ESTATURA:<INPUT TYPE=TEXT NAME=ESTATURA><BR>");
-
-
out.println("<INPUT TYPE=SUBMIT NAME=GRABAR VALUE=INSERTAR ><BR>");
-
-
out.println("</FORM>");
-
-
%>
-
and this is my class - 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;
-
-
-
-
public class imprimir {
-
-
-
/**
-
* Constructor for ReportDriver
-
*/
-
public imprimir() {
-
-
}
-
-
-
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;
-
}
-
-
-
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);
-
}
-
}
-
-
-
-
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;
-
-
} }
-
0 2058 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Eugene A |
last post by:
Hello.
In this call from a Java prog to a Oracle SP I am trying to pass along some
varchars and a cursor, but apperently the syntax of the call to the stor
proc is incorrect. What am I doing...
|
by: Jean-Marc Blaise |
last post by:
Dear all,
I have simulated the windows MULTI application with a java program calling
the SQLTP1DL proc referenced as DB2DARI application, on Linux Intel or
ZLinux. If the proc is NOT FENCED,...
|
by: Samuel |
last post by:
New Prizes for October Jrobots Programming Challenge.
Jrobots is programming game hosted at <http://www.cfxweb.net/~jrobots>
CFXweb.
You play by programming in basic Java your own robot to...
|
by: karen |
last post by:
Hi all :
this is going to be a long post. So i apologize in
advance :)
i am converting a java program in VB right now. I am a
java programmer by trade. so i am no expert in this
department.
I...
|
by: mhust6 |
last post by:
I am trying to call a java method from within my Javascript, but cannot
seem to get it to work. All the examples I have found online and in
the forums are using Java applets. I have a method that...
|
by: Radhakrishnans |
last post by:
hai friends
i am new to java and mysql.i have created stored procedures in mysql.Now i want to call that stored procedures in java.All works fine.but it show the following error.
unreported...
|
by: Steven T. Hatton |
last post by:
I just read §2.11.3 of D&E, and I have to say, I'm quite puzzled by what it
says.
http://java.sun.com/docs/books/tutorial/essential/concurrency/syncrgb.html
<shrug>
--
NOUN:1. Money or...
|
by: BigZero |
last post by:
Hello,
can i call Java method.That is java code from php,here what i m
looking for i have class called DB in this class all the DB related
things ,like DB connection DB insert,DB read etc...
|
by: thatos |
last post by:
I have a java class exe.class I would like to call this program using c.
I tried the following methods none of them seems to work if you know where the problem is please help.
main(){...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |