| Autor |
Mensagem |
|
|
Como trabalhar com relatórios em Java?
|
 |
|
|
|
Galera, o que é Frame Work?
|
 |
|
|
|
Criando um arquivo jar:
<BR>
<BR>1 - Vc sempre cria arquivos jar com os .class da sua aplicação, esqueça os .java
<BR>2 - Crie uma pasta e coloque todos os arquivos .class da sua aplicação, se tiver um arquivo, coloque ele.
<BR>3 - Depois disso entre no Bloco de Notas e crie um arquivo chamado man.txt com o seguinte conteúdo:
<BR>
<BR>Main-Class: <nome da classe que contem o static void main>
<BR>
<BR>4 - Salve o arquivo, lembrando que deve ser salvo na mesma pasta que contem o .class e lembrando que na frente do Main-Class no arquivo man.txt vc nao deve colocar a extensão .class e sim somente o nome do arquivo .class.
<BR>5 - Apos isso vc deve ir ate o Prompt do MS-DOS e entra na pasta que vc criou para rodar o jar, vamos usar a pasta teste como exemplo, então seu prompt ficaria assim:
<BR>c:\>teste>
<BR>6 - Então vc iria dar a seguinte linha de comando, lembrando que o que esta em <> deve ser substituido pelas especificações de sua aplicação:
<BR>
<BR>c:/>teste>jar cvfm <nome do programa>.jar man.txt *.class <pastas que contenham algo que vc use em sua aplicação>
<BR>
<BR>7 - Apos isso, será criado um arquivo .jar em sua pasta, no caso do exemplo, na pasta teste, dai eh soh dar dois cliques no arquivo e pronto ou senão vá ate o pormpt do dos e faça assim:
<BR>
<BR>c:/>teste>java -jar <nome do programa>.jar
<BR>
<BR>
|
 |
|
|
|
Valeu pela dica!!! 8-)
|
 |
|
|
Desejo obter uma documentação sobre as Classes do Java, não todas é claro, mais gostaria de uma documentação que explicasse para que serve uma classe e quais seus objetos e métodos. Já procurei esta documentação em sites de busca mas não encontrei. Tenho algumas dificuldades para programar por não conhecer exatamente o potencial de cada Classe. Por exemplo, a classe AudioClip. Quais são os objetos e métodos que esta classe disponibiliza?
|
 |
|
|
Estudando o JDBC Connector 1.0 vi que ele permite configurar o BD que se quer acessar. Pelo que entendi vc personaliza a classe para acessar seu BD. O documento que li está em inglês mas acho que existe uma interface para configurar a classe, a qual permite que vc escolha a classe e configure. O processo é o seguinte: descompactar o arquivo .zip, depois utilizar o "deployTool". Só que não estou conseguindo utilizar isso. Alguém pode me ajudar? Segue abaixo o tutorial anexo ao JDBC Connector 1.0 para quem quiser dar uma espiada:
<BR>
<BR>************************tutorial anexo baixo***********************
<BR>
<BR>GettingStarted with the JDBCTM Connector :
<BR>
<BR>These step-by-step instructions tell you how to set up the JDBCTM Connector. Note that the instructions are given twice. The first set of instruction is given in a generic way that you need to adapt to your particular deployment tool. The second set applies specifically to using the deploytool utility that is part of the J2EE 1.3.1 Reference Implementation. Once you have finished the deployment tasks, you can run your JDBC applications as usual.
<BR>
<BR>Here are the general steps to follow:
<BR>
<BR>Start your J2EE server
<BR>
<BR>Start the deployment tool for your server
<BR>
<BR>OPEN and EDIT the appropriate JDBC Connector .rar file using the deploy tool
<BR>
<BR>ADD the .jar file or files for your driver
<BR>
<BR>EDIT some of the properties (usually labelled "Configuration Properties" . If your driver uses the DriverManager class to obtain a connection, skip to the last bullet item in this list.
<BR>ServerName - change "value" column so that it contains the IP address of the server where your database is; "localhost" is OK if the DB is on your local machine.
<BR>Username - change to your database user name
<BR>Password - change to your database password
<BR>ClassName - change to the class name for your driver; your driver vendor should supply this
<BR>If your driver uses the DriverManager class to get a connection and if there are any driver-specific properties to be set, edit the value of the DriverProperties config-property. (Otherwise, the value will be blank.) For example, to set the driver URL, you would put in the following: setURL###.
<BR>Example:
<BR>setURL#jdbc:oracle:thin:@localhost:1521:ORCL##.
<BR>
<BR>
<BR>SAVE the .rar file
<BR>
<BR>DEPLOY the .rar file on your server
<BR>
<BR>CREATE a new Connection Factory and Supply the JNDI name to use for a lookup of the DataSource object your application will use to get a connection to the database.
<BR>Do what is comparable on your deployment tool to the following:
<BR>
<BR>Click on or select "Servers" and "localhost" (or your server name if it is not "localhost"
<BR>
<BR>Create a new Connection Factory, usually by clicking a "Resource Adapters" tab or button and then clicking "New". You may see something labelled "New Connection Factory". You should see a place to type in a name of your choosing to identify your database.
<BR>
<BR>Type in "jdbc/" followed by any unique name you choose for your database. Example: "jdbc/EmpDB"
<BR>This name will be registered with a JNDI naming service and can be used to retrieve the implementation that will create a connection to your database.
<BR>
<BR>SAVE, click "OK", or whatever is comparable on your deployment tool
<BR>Here are the instructions for using the deploytool that is part of the J2EE Reference Implementation
<BR>This section details using one of the JDBC Connector RAR files with the J2EE Reference Implementation and connecting to a driver. This document is based on using J2EE 1.3.1; the JDBC Connector also works with J2EE 1.4.
<BR>Prerequisites
<BR>Before getting started, you need to need to have the following set up.
<BR>The JDBC Connector (downloaded from Sun´s JDBC site and unzipped in your local drive).
<BR>The J2EE Reference Implementation (1.3.1). If you do not already have it, download it from Sun´s J2EE web site and install it.
<BR>A driver based on JDBC technology ("JDBC driver" for the database you want to use. You will find a list of JDBC drivers on the JDBC drivers page.
<BR>Steps for Setting Up the JDBC Connector
<BR>Start the J2EE application server.
<BR>Start the J2EE deploytool. See <a href="http://java.sun.com/j2ee/sdk_1.3/techdocs/release/ReleaseNotes.html" target="_blank" target="_new">http://java.sun.com/j2ee/sdk_1.3/techdocs/release/ReleaseNotes.html</a> if you need more information.
<BR>OPEN the appropriate JDBC Connector .rar file using the deploy tool. This example shows using an _xa RAR file, which is appropriate if your driver uses an XADataSource implementation to get a connection and thus enables distributed transactions.
<BR>For J2EE 1.3.1, open spi_10_xa.rar
<BR>For J2EE 1.4, open spi_15_xa.rar
<BR>
<BR>In the right pane of deploytool, click on the "RAR File" tab. Click EDIT. Add the .jar file or files for your JDBC driver. Your driver documentation should tell you what file(s) to use. In some cases, you might need to change the name of a file from .zip to .jar before adding it.
<BR>In the right pane, click on the "Configuration Properties" tab and edit some of the properties in the table.
<BR>Change the value of the property ServerName to the IP address of your database server.
<BR>Change the value of UserName and Password to your database user name and password.
<BR>Change the value of ClassName so that it is the class name of the XADataSource implementation for your driver.
<BR>SAVE the .rar file .
<BR>DEPLOY the .rar file from the deploytool.
<BR>In the left pane of deploytool, under the "Servers" tree, click on "localhost". Then, in the right pane, click on the "Resource Adapters" tab and and click "New".
<BR>Put in a suitable "ConnectionFactory JNDI Name". This name should be "jdbc/" followed by any unique name you want to use to identify your database. For example, you could use "jdbc/EmpDB".
<BR>You have successfully deployed your first JDBC Connector resource adapter. Now you are ready to run your database applications the same way you usually do.
<BR>
<BR>Sample Code
<BR>Here is some sample code for retrieving the DataSource object that will create a connection to your database. This code fragment assumes that you entered "jdbc/EmpDB" as your ConnectionFactory JNDI name.
<BR>
<BR>Context ctx = new InitialCcontext();
<BR>DataSource ds = (DataSource)ctx.lookup("jdbc/EmpDB" ;
<BR>Connection con = ds.getConnection();
<BR>
<BR>PreparedStatement pstmt = con.prepareStatement(
<BR>"SELECT NAME, TITLE FROM EMPLOYEES WHERE DEPT = ?" ;
<BR>pstmt.setString(1, "SALES" ;
<BR>ResultSet rs = pstmt.executeQuery();
<BR>. . .//rest of your application
|
 |
|
|
|
Obrigado! Vou analisar o código. Um abraço!<BR><BR>[ Esta mensagem foi editada por: Francesco em 13-04-2003 11:44 ]
|
 |
|
|
|
Então encontro aqui como utilizar estas classes para fazer a conexão! No caso então a conexão é direta e não precisa de mais nada, somente indicar o BD que eu quero? No momento estou com uma conexão com o Access através de ODBC. Usando essa API posso eliminar essa necessidade? Aguardo repsosta. Francesco. 8-)
|
 |
|
|
Encontrei no site da Sun o JDBC Coonector 1.0 e pelo que eu entendi, é possível fazer conexão com banco de dados sem codificação, apenas utilizaríamos as classes do pacote JDBC Connector. Eu não tive tempo de ler direito. É isso mesmo? Alguém aqui sabe usar esse recurso? Aguardo respostas.
|
 |
|
|
Peço também que mandem uma apostila de JDBC, mais com muito estudo consegui uma conexão com o MS Access com leitura de registros. Vai aí o código:
<BR><nauta.bp@ig.com.br>
<BR>
<BR>import java.sql.*;
<BR>import java.util.*;
<BR>
<BR>public class testesql
<BR>{
<BR> private static Statement statement = null;
<BR> private static Connection conexao = null;
<BR> private String URL = "jdbc:odbc:meudb";
<BR>
<BR> public testesql()
<BR> {
<BR> super();
<BR> try
<BR> {
<BR> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver" ;
<BR> conexao = DriverManager.getConnection(URL, "", "" ;
<BR>}
<BR> catch (SQLException sql1)
<BR> {
<BR> sql1.printStackTrace();
<BR> conexao = null;
<BR> }
<BR> catch (ClassNotFoundException clas)
<BR> {
<BR> System.out.println("Ex2" ;
<BR> clas.printStackTrace();
<BR> conexao = null;
<BR> }
<BR>}
<BR>
<BR>public String Select(String QueryLine)
<BR>{
<BR>
<BR> String Output = "";
<BR> int columns;
<BR> int pos;
<BR> try
<BR>{
<BR>
<BR>Statement stmt = conexao.createStatement();
<BR>
<BR>System.out.println(QueryLine);
<BR>ResultSet rs = stmt.executeQuery(QueryLine);
<BR>columns = (rs.getMetaData()).getColumnCount();
<BR>
<BR>while (rs.next())
<BR>{
<BR> for (pos = 1; pos <= columns; pos++)
<BR> {
<BR> Output += rs.getObject(pos) + " ";
<BR> }
<BR> Output += " ";
<BR>}
<BR>
<BR> stmt.close();
<BR>}
<BR> catch (SQLException e)
<BR> {
<BR> e.printStackTrace();
<BR> Output = e.getMessage();
<BR> }
<BR> return Output;
<BR>}
<BR>
<BR>public static void main(String[] args)
<BR>{
<BR> testesql teste = new testesql();
<BR>
<BR> String query = "SELECT id,nome,turno FROM empregados where nome = ´Francesco´";
<BR> System.out.println(teste.Select(query));
<BR>}
<BR>}
<BR>
|
 |
|
|
|
Tem alguma coisa do genero aí para o MS Access? :-?
|
 |
|
|
|
Não sei isso pode ajudar, mas é possível em sua aplicação contar os itens para depois criar o array? Vc poderia criar um array com o número de itens classificados. :-? . Sou iniciante em java mais pensando "algoritmicamente" me veio está solução.
|
 |
|
|
O seguinte código funcionou comigo, fiz a mesma coisa que vc na configuração ODBC do banco de dados.
<BR>import java.sql.*;
<BR>import java.util.*;
<BR>
<BR>public class testesql
<BR>{
<BR> private static Statement statement = null;
<BR> private static Connection conexao = null;
<BR> private String URL = "jdbc:odbc:meudb";
<BR>
<BR> public testesql()
<BR> {
<BR> super();
<BR> try
<BR> {
<BR> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver" ;
<BR> conexao = DriverManager.getConnection(URL, "", "" ;
<BR>}
<BR> catch (SQLException sql1)
<BR> {
<BR> sql1.printStackTrace();
<BR> conexao = null;
<BR> }
<BR> catch (ClassNotFoundException clas)
<BR> {
<BR> System.out.println("Ex2" ;
<BR> clas.printStackTrace();
<BR> conexao = null;
<BR> }
<BR>}
<BR>
<BR>public String Select(String QueryLine)
<BR>{
<BR>
<BR> String Output = "";
<BR> int columns;
<BR> int pos;
<BR> try
<BR>{
<BR>
<BR>Statement stmt = conexao.createStatement();
<BR>
<BR>System.out.println(QueryLine);
<BR>ResultSet rs = stmt.executeQuery(QueryLine);
<BR>columns = (rs.getMetaData()).getColumnCount();
<BR>
<BR>while (rs.next())
<BR>{
<BR> for (pos = 1; pos <= columns; pos++)
<BR> {
<BR> Output += rs.getObject(pos) + " ";
<BR> }
<BR> Output += " ";
<BR>}
<BR>
<BR> stmt.close();
<BR>}
<BR> catch (SQLException e)
<BR> {
<BR> e.printStackTrace();
<BR> Output = e.getMessage();
<BR> }
<BR> return Output;
<BR>}
<BR>
<BR>public static void main(String[] args)
<BR>{
<BR> testesql teste = new testesql();
<BR>
<BR> String query = "SELECT id,nome,turno FROM empregados where nome = ´Francesco´";
<BR> System.out.println(teste.Select(query));
<BR>}
<BR>}
<BR> 8-)
|
 |
|
|
Utilizei um código de um livro java para fazer o que você fez. Alias o seu código anterior deu uma ajuda boa para eu estudar, valeu! Funciona apenas no prompt, basta compilar. Dá uma espiada:
<BR>
<BR>import java.sql.*;
<BR>import java.util.*;
<BR>
<BR>public class testesql
<BR>{
<BR> private static Statement statement = null;
<BR> private static Connection conexao = null;
<BR> private String URL = "jdbc:odbc:meudb";
<BR>
<BR> public testesql()
<BR> {
<BR> super();
<BR> try
<BR> {
<BR> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver" ;
<BR> conexao = DriverManager.getConnection(URL, "", "" ;
<BR>}
<BR> catch (SQLException sql1)
<BR> {
<BR> sql1.printStackTrace();
<BR> conexao = null;
<BR> }
<BR> catch (ClassNotFoundException clas)
<BR> {
<BR> System.out.println("Ex2" ;
<BR> clas.printStackTrace();
<BR> conexao = null;
<BR> }
<BR>}
<BR>
<BR>public String Select(String QueryLine)
<BR>{
<BR>
<BR> String Output = "";
<BR> int columns;
<BR> int pos;
<BR> try
<BR>{
<BR>
<BR>Statement stmt = conexao.createStatement();
<BR>
<BR>System.out.println(QueryLine);
<BR>ResultSet rs = stmt.executeQuery(QueryLine);
<BR>columns = (rs.getMetaData()).getColumnCount();
<BR>
<BR>while (rs.next())
<BR>{
<BR> for (pos = 1; pos <= columns; pos++)
<BR> {
<BR> Output += rs.getObject(pos) + " ";
<BR> }
<BR> Output += " ";
<BR>}
<BR>
<BR> stmt.close();
<BR>}
<BR> catch (SQLException e)
<BR> {
<BR> e.printStackTrace();
<BR> Output = e.getMessage();
<BR> }
<BR> return Output;
<BR>}
<BR>
<BR>public static void main(String[] args)
<BR>{
<BR> testesql teste = new testesql();
<BR>
<BR> String query = "SELECT id,nome,turno FROM empregados where nome = ´Francesco´";
<BR> System.out.println(teste.Select(query));
<BR>}
<BR>}
<BR> 8-) <!-- BBCode Start --><A HREF="mailto:nauta.bp@ig.com.br">nauta.bp@ig.com.br</A><!-- BBCode End -->
|
 |
|
|
|
Preciso desenvolver uma applet que funcionará a nível local com um banco de dados. Deverão ser feitas consultas e exibidos os resultados encontrados. A applet estará em uma página. Está página contém uma opção de pesquisa por palavra chave. Como posso fazer isso?<!-- BBCode Start --><A HREF="mailto:nauta.bp@ig.com.br">nauta.bp@ig.com.br</A><!-- BBCode End -->
|
 |
|
|