Re: JDBC para MSQL2000

3 respostas
_fs

Recordset?

Pode mostrar o seu código?

3 Respostas

_fs

ah rapaz, coloca as linhas pertinentes na próxima vez, né? :smiley:

Bom, o mais próximo que encontrei foi isso:
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ResultSet.html#refreshRow()

E alguns apontamentos:

A

Ai pessoal estou com um problema gostaria de saber se alguem já passou por isso, O negócio é o seguinte, Qdo faço Alteração, Exclusão ou Inclusão de registro pelo Recordset o banco é atualizado mas o Recordset ocontinua com os valores originais, so atualiza qdo fecho e abro a conexão novemente. Como posso dar um Refresh do RS ??? - Estou usado
J2SE - JDBC 2.2 for MSQL2000 plataforma W2000 - Eclipse

Valeu

A
Ae está o cósigo Lipe, valeu pela atenção meu camarada!!!! :D
public class Clientes {
	
	//SWT;
	private org.eclipse.swt.widgets.Shell sShell = null;
	private Composite JCOMP_COMPOSITE = null;
	
	//Java Text Fields;
	private Text JTF_CPF = null;
	private  Text JTF_NOME = null;
	private Text JTF_ENDEREÇO = null;
	
	//Java Labels;
	private Label JLBL_CPF = null;
	private Label JLBL_NOME = null;
	private Label JLBL_ENDEREÇO = null;
	
	//Java Buttons; 
	private Button JBUT_INCLUIR = null;
	private Button JBUT_EXCLUIR = null;
	private Button JBUT_MOVE_LEFT = null;
	private Button JBUT_SAIR = null;
	
	private Button JBUT_MOVE_RIGHT = null;

	public ResultSet rs = null;
	public SQL2000 cn = new SQL2000();
	
	
	public Clientes() {
                         super();
	}

    private void createSShell() {
		sShell = new org.eclipse.swt.widgets.Shell();		   
		createComposite();
		sShell.setText("Cadastro de Clientes");
		sShell.setSize(new org.eclipse.swt.graphics.Point(517,190));
		sShell.setVisible(true);
	}
	/**
	 * 
	 *  Inicialização do Composite;
	 */
	private void createComposite() {
		
		JCOMP_COMPOSITE = new Composite(sShell, SWT.NONE);
		JCOMP_COMPOSITE.setBounds(new org.eclipse.swt.graphics.Rectangle(-2,1,515,159));
		
		//CPF;
		JTF_CPF = new Text(JCOMP_COMPOSITE, SWT.BORDER);
		JTF_CPF.setBounds(new org.eclipse.swt.graphics.Rectangle(124,27,182,20));
		JLBL_CPF = new Label(JCOMP_COMPOSITE, SWT.NONE);
		JLBL_CPF.setBounds(new org.eclipse.swt.graphics.Rectangle(45,29,45,18));
    	JLBL_CPF.setText("CPF:");
		
		//NOME;
		JTF_NOME = new Text(JCOMP_COMPOSITE, SWT.BORDER);
		JLBL_NOME = new Label(JCOMP_COMPOSITE, SWT.NONE);
		JTF_NOME.setBounds(new org.eclipse.swt.graphics.Rectangle(124,51,297,21));
		JLBL_NOME.setBounds(new org.eclipse.swt.graphics.Rectangle(45,56,78,20));
		JLBL_NOME.setText("Nome:");
		
		
		//ENDEREÇO
		JTF_ENDEREÇO = new Text(JCOMP_COMPOSITE, SWT.BORDER);
		JLBL_ENDEREÇO = new Label(JCOMP_COMPOSITE, SWT.NONE);
		JLBL_ENDEREÇO.setBounds(new org.eclipse.swt.graphics.Rectangle(44,80,78,16));
		JTF_ENDEREÇO.setLocation(new org.eclipse.swt.graphics.Point(124,76));
		JTF_ENDEREÇO.setSize(new org.eclipse.swt.graphics.Point(296,21));
		JLBL_ENDEREÇO.setText("Endereço:");
		
		
		//INCLUIR REGISTROS
		JBUT_INCLUIR = new Button(JCOMP_COMPOSITE, SWT.NONE);
		JBUT_INCLUIR.setLocation(new org.eclipse.swt.graphics.Point(431,16));
		JBUT_INCLUIR.setSize(new org.eclipse.swt.graphics.Point(65, 26));
		
		JBUT_INCLUIR.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() { 
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {    
				try {
					int   CPF = Integer.parseInt(Clientes.this.JTF_CPF.getText());
					String NOME = Clientes.this.JTF_NOME.getText();
				    String END  = Clientes.this.JTF_ENDEREÇO.getText();  
					
					rs.moveToInsertRow(); 
					
					rs.updateInt(1,CPF);
					rs.updateString(2,NOME); 
					rs.updateString(3,END); 
					rs.updateString(4,""); 
					rs.insertRow();
				  }
				  catch (SQLException e1) 
				  {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				  }	
			}
		});
		
		
		JBUT_EXCLUIR = new Button(JCOMP_COMPOSITE, SWT.NONE);
		
		JBUT_MOVE_LEFT = new Button(JCOMP_COMPOSITE, SWT.NONE);
		JBUT_SAIR = new Button(JCOMP_COMPOSITE, SWT.NONE);
		JBUT_MOVE_RIGHT = new Button(JCOMP_COMPOSITE, SWT.NONE);

		
		//Determinia o tamanho e o posicionamento dos componentes;
		
		JBUT_EXCLUIR.setLocation(new org.eclipse.swt.graphics.Point(431,48));
		JBUT_EXCLUIR.setSize(new org.eclipse.swt.graphics.Point(65,26));
		JBUT_MOVE_LEFT.setBounds(new org.eclipse.swt.graphics.Rectangle(28,135, 22, 20));
		JBUT_SAIR.setSize(new org.eclipse.swt.graphics.Point(65,26));
		JBUT_SAIR.setLocation(new org.eclipse.swt.graphics.Point(431,128));
		JBUT_MOVE_RIGHT.setText(">");
		JBUT_MOVE_RIGHT.setLocation(new org.eclipse.swt.graphics.Point(55,135));
		JBUT_MOVE_RIGHT.setSize(new org.eclipse.swt.graphics.Point(22,20));
		
		JBUT_MOVE_RIGHT.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() { 
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {    
				try {
					if (Clientes.this.rs.isLast()==false) {
					   Clientes.this.rs.next();
					   Clientes.this.CarregaCampos();	
					}else 
					{
						Clientes.this.rs.first();
						Clientes.this.CarregaCampos();
					}
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}				
			}
		});
		JBUT_MOVE_LEFT.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() { 
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {    
				try {
					if (Clientes.this.rs.isFirst()==false) {
					   Clientes.this.rs.previous();
					   Clientes.this.CarregaCampos();	
					}else 
					{
						Clientes.this.rs.last();
						Clientes.this.CarregaCampos();
					}
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		
		JBUT_EXCLUIR.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() { 
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {    
				try {
					rs.deleteRow();
					Clientes.this.CarregaCampos();
				  }
				  catch (SQLException e1) 
				  {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				  }	

			}
		});
		
		JBUT_SAIR.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() { 
			
		public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {    
				System.exit(0);
			}
		});
		
		JBUT_INCLUIR.setText("Incluir");
		JBUT_EXCLUIR.setText("Excluir");
		JBUT_MOVE_LEFT.setText("<");
		JBUT_SAIR.setText("Sair");
	}
	
	public void CarregaCampos() 
	{
		 try 
		 {
		 	Clientes.this.JTF_CPF.setText(Clientes.this.rs.getString("CPF"));
			Clientes.this.JTF_NOME.setText(Clientes.this.rs.getString("NOME"));
			Clientes.this.JTF_ENDEREÇO.setText(Clientes.this.rs.getString("ENDEREÇO"));	
         } 
        catch (SQLException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {				
		
		org.eclipse.swt.widgets.Display display = org.eclipse.swt.widgets.Display.getDefault();		
		Clientes thisClass = new Clientes();
		thisClass.createSShell();
		thisClass.sShell.open();
		
		thisClass.rs = thisClass.cn.Executa("Select * from Clientes");

		 try 
		 {
			thisClass.rs.first();
	        thisClass.rs.next();
	        thisClass.CarregaCampos();	
         } 
         catch (SQLException e) 
		 {
			// TODO Auto-generated catch block
			e.printStackTrace();
		 }
	
		while (!thisClass.sShell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep ();
		}
		
		display.dispose();	
		

		
		
		
		
	}	
	

}
Criado 1 de junho de 2005
Ultima resposta 1 de jun. de 2005
Respostas 3
Participantes 2