473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

How I call a java class from my jsp.. please

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

Expand|Select|Wrap|Line Numbers
  1. <%@ page import="java.io.*,java.util.*,java.net.*,java.sql.*,imprimir.imprimir" %>
  2.  
  3. <%
  4.  
  5.  
  6. if(request.getParameter("GRABAR") != null)
  7.  
  8. {
  9.  
  10. // objetos de enlace
  11.  
  12. Connection canal = null;
  13.  
  14. ResultSet tabla= null;
  15.  
  16. Statement instruccion=null;
  17.  
  18.  
  19. // abriendo canal o enlace en su propio try-catch
  20.  
  21. try {
  22.  
  23. Class.forName("com.mysql.jdbc.Driver").newInstance();
  24.  
  25. canal=DriverManager.getConnection("jdbc:mysql:///cablevision_atc", "root", "");
  26.  
  27. instruccion = canal.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
  28.  
  29. ResultSet.CONCUR_UPDATABLE);
  30.  
  31. } catch(java.lang.ClassNotFoundException e){} catch(SQLException e) {};
  32.  
  33. //cargando los campos a grabar
  34.  
  35. // excepto clave porque en mysql es de tipo auto-increment
  36.  
  37. int estado = 0;
  38.  
  39.  
  40. String q="insert into ticket(estado_ticket) values(\"" +estado+"\"); ";
  41.  
  42. try {
  43.  
  44. // agregando renglon (insert)
  45.  
  46. int n=instruccion.executeUpdate(q);
  47.  
  48. //avisando que se hizo la instruccion
  49.  
  50. out.println("REGISTRO INSERTADO");
  51.  
  52. imprimir print = new imprimir();
  53.  
  54.  
  55.  
  56.  
  57. } catch(SQLException e) {out.println(e);};
  58.  
  59. try{
  60.  
  61. // tabla.close();
  62.  
  63. instruccion.close();
  64.  
  65. canal.close();
  66.  
  67. } catch(SQLException e) {out.println(e);};
  68.  
  69. };
  70.  
  71.  
  72.  
  73.  
  74. // construyendo forma dinamica
  75.  
  76. out.println("<FORM ACTION=index.jsp METHOD=post>");
  77.  
  78. //out.println("NOMBRE :<INPUT TYPE=TEXT NAME=NOMBRE><BR>");
  79.  
  80. //out.println("EDAD :<INPUT TYPE=TEXT NAME=EDAD><BR>");
  81.  
  82. //out.println("ESTATURA:<INPUT TYPE=TEXT NAME=ESTATURA><BR>");
  83.  
  84. out.println("<INPUT TYPE=SUBMIT NAME=GRABAR VALUE=INSERTAR ><BR>");
  85.  
  86. out.println("</FORM>");
  87.  
  88. %>
  89.  
and this is my class

Expand|Select|Wrap|Line Numbers
  1. package imprimir;
  2.  
  3. import java.sql.*;
  4. import net.sf.jasperreports.engine.xml.JRXmlLoader;
  5. import net.sf.jasperreports.engine.JasperCompileManager;
  6. import net.sf.jasperreports.engine.JasperFillManager;
  7. import net.sf.jasperreports.engine.JasperPrint;
  8. import net.sf.jasperreports.engine.design.JasperDesign;
  9. import net.sf.jasperreports.engine.JasperReport;
  10. import net.sf.jasperreports.view.JasperViewer;
  11.  
  12.  
  13.  
  14. public class imprimir {
  15.  
  16.  
  17.     /**
  18.      * Constructor for ReportDriver
  19.      */
  20.     public imprimir() {
  21.  
  22.     }
  23.  
  24.  
  25.     public static Connection connectDB(String databaseName, String userName, String password) {
  26.         Connection jdbcConnection = null;
  27.         try{
  28.             Class.forName("com.mysql.jdbc.Driver").newInstance ();
  29.             jdbcConnection = DriverManager.getConnection("jdbc:mysql:///cablevision_atc", "root", "");
  30.         }catch(Exception ex) {
  31.             String connectMsg = "Could not connect to the database: " + ex.getMessage() + " " + ex.getLocalizedMessage();
  32.             System.out.println(connectMsg);
  33.         }
  34.         return jdbcConnection;
  35.     }
  36.  
  37.  
  38.     public static void runReport(String databaseName, String userName, String password,String reportFile) {
  39.         try{
  40.             JasperDesign jasperDesign = JRXmlLoader.load(reportFile);
  41.             JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
  42.             Connection jdbcConnection = connectDB(databaseName, userName, password);
  43.             JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, jdbcConnection);
  44.             JasperViewer.viewReport(jasperPrint);
  45.             //JasperPrintManager.printPages(jasperPrint,0,jasperPrint.getPages().size()-1,true);
  46.  
  47.  
  48.         }catch(Exception ex) {
  49.             String connectMsg = "Could not create the report " + ex.getMessage() + " " + ex.getLocalizedMessage();
  50.             System.out.println(connectMsg);
  51.         }
  52.     }
  53.  
  54.  
  55.  
  56.     public static void main(String[] args) {
  57.  
  58.             String databaseName = "cablevision_atc";
  59.             String userName = "root";
  60.             String password = "";
  61.             String reportFile = "C:\\wamp\\www\\Cablevision\\JAVA\\ticket.jrxml";
  62.  
  63.             runReport(databaseName, userName, password, reportFile);
  64.  
  65.         return;
  66.  
  67.     } }
  68.  
Dec 29 '09 #1
0 2058

Sign in to post your reply or Sign up for a free account.

Similar topics

6
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...
4
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,...
6
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...
12
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...
2
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...
1
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...
46
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...
11
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...
2
thatos
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(){...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.