Results 1 to 6 of 6
  1. #1
    kike_skate is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Question Show data from PostgreSQL

    Hi there ..

    Im new in java ... i want to show some data from a data base that it was create en postgresql.

    Im using a framework that is called ZK i made my model of my page with this framework.

    Now i create a class to connect Postgre with Java ... but now i don't now what to do! i have to create another class to show the data???

    Please any helps is good links or maybe examples!!

    Another question how can i do to prove my code if the connection i made is working???

    This my code of connection
    Java Code:
    package conexion;
    
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.UUID;
    
    
    
    public class EventoDAO {
    
    	private String url = "jdbc:postgresql://localhost:5432/usuarios";
    
    	private String user = "postgres";
    
    	private String pwd = "nino1n";
    
    	public EventoDAO() {
    		try {
    			Class.forName("org.postgresql.Driver");
    		} catch (ClassNotFoundException e) {
    			e.printStackTrace();
    		}
    	}
    
    	
    	@SuppressWarnings({ "rawtypes", "unchecked" })
    	public List findAll(){
    		Statement stmt = null;
    		Connection conn = null;
    		List allEvents = new ArrayList();
    		try {
    			// get connection
    			conn = DriverManager.getConnection(url, user, pwd);
    			stmt = conn.createStatement();
    			ResultSet rs = stmt.executeQuery("select * from usua");
    
    			// fetch all events from database
    			Evento evt;
    			while (rs.next()) {
    				evt = new Evento();
    				evt.setId(rs.getString(1));
    		        evt.setCharge(rs.getString(2));
    				evt.setMail(rs.getInt(3));
    				evt.setMobile(rs.getString(4));
    				evt.setPassword(rs.getString(5));
    
    				allEvents.add(evt);
    			}
    			
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}finally{
    			try {
    				stmt.close();
    			} catch (SQLException e) {
    				e.printStackTrace();
    			}
    			try {
    				conn.close();
    			} catch (SQLException e) {
    				e.printStackTrace();
    			}
    		}		
    		return allEvents;
    	}
    		
    	
    	public boolean insert(Evento evt){
    		Connection conn = null;
    		Statement stmt = null;
    		boolean result = false;
    		try {
    			// get connection
    			conn = DriverManager.getConnection(url, user, pwd);
    			stmt = conn.createStatement();
    			if (stmt.executeUpdate("insert into usua(id,charge,mail,mobile,password) " +
    					"values ('" + UUID.randomUUID().toString() + "','" + evt.getCharge() +
    					"'," + evt.getMail() +   "','" + evt.getMobile()+  "','" + evt.getPassword() +  "')") > 0);
    			result = true;
    			
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}finally{
    			try {
    				stmt.close();
    			} catch (SQLException e) {
    				e.printStackTrace(); 
    			}
    			try {
    				conn.close();
    			} catch (SQLException e) {
    				e.printStackTrace();
    			}
    		}
    		
    		return result;
    	}
    	
    }

    This is my code of ZK Framework were i want to show the data of the table

    XML Code:
    <?page title="Previous Executed Jobs" contentType="text/html;charset=UTF-8"?>
    <zk>
    <style>
        body {  
               background-image: url('images/fondos.jpg'); 
               
              }		
    </style>
    
    <window>
    	
    	<include src="vprincipal.zul"/> 
    	 
    </window>
    
    <window title="Previus Jobs Executed" border = "normal">
    
    <grid mold="paging" pageSize="10" >
    		<columns>
    			<column label="Execution ID"/>
    			<column label="Start Date"/>
    			<column label="End Date"/>
    			<column label="Start Hour"/>
    			<column label="End Hour"/>
    			<column label="Ingest Rawdata" width="100px"/>
    			<column label="Export Presence" width="120px"/>
    			<column label="Export Flows" width="100px"/>
    			<column	label= "Rasterizat" width="100px"/>		
    		</columns>
    		<rows>	
    		
    			
    		
    			<row forEach="${orderArray}">
    				
    				<label value="submit()" id="id"/>
    				<label value="submit()" id="s_date"/>
    				<label value="submit()" id="e_date"/>
    				<label value="submit()" id="s_hour"/>
    				<label value="submit()" id="e_hour"/>
    				<label value="submit()" id="in_raw"/>
    				<label value="submit()" id="ex_presen"/>
    				<label value="submit()" id="ex_flow"/>
    				<label value="submit()" id="raste"/>				
    			</row>
    			
    			<row>
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    			</row>
    		
    			<row>
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    			</row>
    			
    			<row>
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    			</row>
    			
    			<row>
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    			</row>
    			
    			<row>
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    			</row>
    			
    			<row>
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    			</row>
    			
    
    			
    			<row>
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    				<label value="" />
    			</row>
    			
    			
    		
    		
    		</rows>
    	</grid>
    	
    	
    	
    	
    	<div  align="center"> 
    		<button label=" Process " onClick="" width="90px"/>
    	</div>
    
    </window>
    And this is what i have on my table PostgreSQL

    Java Code:
    -- Table: pre_
    
    -- DROP TABLE pre_;
    
    CREATE TABLE pre_
    (
      id name,
      s_date date,
      e_date date,
      s_hour interval,
      e_hour interval,
      in_raw numeric,
      ex_presen numeric,
      ex_flow numeric,
      raste numeric
    )
    WITH (OIDS=FALSE);
    ALTER TABLE pre_ OWNER TO postgres;

    Thanks! for the help!!!!!
    :(

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    The data is stored in the ResultSet that's created after executing a query. You can display it any way you like - as text, make graphs, console output, whatever. How would you like to display the data?

  3. #3
    kike_skate is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default

    first of implement how do i know if my connection of my java class is working with my DB Postgres fine.

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    How do you know if the DB connection is working? Well, if you get no exceptions and if the result set actually contains records, then it's working.

  5. #5
    kike_skate is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default

    Java Code:
    package pre_eventos;
    
    import org.zkoss.zk.ui.Component;
    
    @SuppressWarnings("unused")
    public class EventoPre {
    	
    	private String id;
    	private String s_date;
    	private String e_date; 
    	private String s_hour; 
    	private String e_hour;
    	private String in_raw;
    	private String ex_presen;
    	private String ex_flow;
    	private String raste; 
    	
    
    	public EventoPre(){}	
    	
    	public EventoPre(String id,String s_date,String e_date,String s_hour, String e_hour, String in_raw, String ex_presen, String ex_flow, String raste ){
    
    		this.id = id;
    		this.s_date = s_date;
    		this.e_date = e_date;
    		this.s_hour = s_hour;
    		this.e_hour = e_hour;
    		this.in_raw = in_raw;
    		this.ex_presen = ex_presen;
    		this.ex_flow = ex_flow;
    		this.raste = raste;
    		
    	}
    	public String getId() {
    		return id;
    	}
    	public void setId(String id) {
    		this.id = id;
    	}
    		
    	public String gets_date() {
    		return s_date;
    	}	
    	public void sets_date(String s_date){
    		this.s_date = s_date;
    		
    	}
    	public String gete_date() {
    		return e_date;
    	}
    	public void sete_date(String e_date) {
    		this.e_date = e_date;
    	}
    	
    	public String gets_hour() {
    		return s_hour;
    	
    	}
    	public void sets_hour(String s_hour) {
    		this.s_hour = s_hour;
    
    	}	
    
    	public String gete_hour () {
    		return e_hour;
    	}
    	public void sete_hour(String e_hour) {
    		this.e_hour = e_hour;
    	}
    
    	public String getin_raw() {
    		return in_raw;
    	}
    	public void setin_raw(String in_raw) {
    		this.in_raw = in_raw;
    	
    	}
    	public String getex_presen() {
    		return ex_presen;
    	}
    	public void seten_presen(String ex_presen) {
    		this.ex_presen = ex_presen;
    	}
    	public String getex_flow() {
    		return ex_flow;
    	}
    	public void setex_flow(String ex_flow) {
    		this.ex_flow = ex_flow;
    	}
    	public String getrasastete() {
    		return raste;
    	}
    	public void setraste(String raste) {
    		this.raste = raste;
    	}

    Java Code:
    package pre_eventos;
    
    
    
    import org.zkoss.zk.ui.util.GenericForwardComposer;
    import org.zkoss.zkplus.databind.AnnotateDataBinder;
    import org.zkoss.zul.Listbox;
    import java.util.List;
    
    import conexion.Evento;
    import conexion.EventoDAO;
    
    
    public class PreControlador extends GenericForwardComposer {
    
    	private static final long serialVersionUID = 1L;
    
    	protected AnnotateDataBinder binder;
    	
    	ConexionPre ConePre = new ConexionPre();
    	EventoPre current = new EventoPre();
    	Listbox box;
    	
    	public EventoPre getCurrent() {
    		return current;
    	}
    	public void setCurrent(EventoPre current) {
    		this.current = current;
    
    	}
    	}
    }
    What do u thinkg is missing ??? .
    Last edited by kike_skate; 05-18-2011 at 06:43 PM.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,422
    Rep Power
    20

    Default

    What do u thinkg is missing ??? .
    A specific question.

    Two extra question marks don't make up for that.

    db

Similar Threads

  1. Replies: 2
    Last Post: 03-29-2011, 12:08 PM
  2. Replies: 3
    Last Post: 05-27-2010, 10:54 AM
  3. How to show class initialize data in JSP ?
    By tking88 in forum New To Java
    Replies: 0
    Last Post: 03-07-2010, 09:17 AM
  4. Data from a model class won't show up in the table
    By ayampanggang in forum AWT / Swing
    Replies: 3
    Last Post: 11-27-2008, 08:20 PM
  5. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 06:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •