Search Results

Search found 3 results on 1 pages for 'akcire atienza'.

Page 1/1 | 1 

  • retrieving value from database in java

    - by Akcire Atienza
    I am making AGAIN another program that retrieves the inputted data/values of fields from the database I created. but this time, my inputted value will be coming from the JtextField I created. I wonder what's wrong in here bec when I'm running it the output is always null. in this program i will convert the inputted value of my JTextField into int. here it is: public class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { if(e.getSource() == extendB) { ExtensionForm extend = new ExtensionForm(); extend.setVisible(true); } else if(e.getSource()== searchB) { //get text from the textField String guest = guestIDTF.getText(); //parse the string to integer for retrieving of data int id = Integer.parseInt(guest); GuestsInfo guestInfo = new GuestsInfo(id); Room roomInfo = new Room(id); String labels[] = {guestInfo.getFirstName()+" "+guestInfo.getLastName(),""+roomInfo.getRoomNo(),roomInfo.getRoomType(),guestInfo.getTime(),"11:00"}; for(int z = 0; z<labels.length; z++) { labelDisplay[z].setText(labels[z]); } in my second class it retrieves the inputted values of fields from the database I created here's the code: import java.sql.*; public class Room { private String roomType; private int guestID, roomNo; private Connection con; private PreparedStatement statement; public Room(){ try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/3moronsdb","root",""); } catch (Exception e) { e.printStackTrace(); } } public Room(int guestsID) { this(); try{ statement = con.prepareStatement("SELECT * FROM guest WHERE guestID=?"); statement.setInt(1, guestID); ResultSet rs = statement.executeQuery(); while(rs.next()){ this.guestID = rs.getInt(1); this.roomType = rs.getString(2); this.roomNo = rs.getInt(3); } }catch(Exception e){ System.out.print(e); } } //Constructor for setting rate public Room(String roomType, int roomNo) { this(); try { statement = con.prepareStatement("Insert into room(roomType, roomNo) values(?,?)"); statement.setString(1, roomType); statement.setInt(2, roomNo); statement.executeUpdate(); } catch(Exception e) { e.printStackTrace(); return; } } //getting roomType public String getRoomType(){ return roomType; } //getting roomNo public int getRoomNo(){ return roomNo; } //getting guestID public int getGuestId(){ return guestID; } } i already insert some values in my 3moronsdb which are ( 1, Classic , 103). here's my TEST main class: public class TestMain { public static void main(String [] a){ GuestsInfo guest = new GuestsInfo(1); //note that this instantiation is the other class which i just ask the other day.. (http://stackoverflow.com/questions/12762835/retrieving-values-from-database-in-java) Room rum = new Room(1); System.out.print(rum.getRoomType()+" "+ guest.getFirstName()); } } when i'm running it it only gives me null output for the Room class but i am getting the output of the GuestsInfo class which is 'Ericka'. Can you help me guys? I know I ask this kind of problem yesterday but i really don't know what's wrong in here now..

    Read the article

  • Getting past dates in HP-UX with ksh

    - by Alejandro Atienza Ramos
    Ok, so I need to translate a script from a nice linux & bash configuration to ksh in hp-ux. Each and every command expects a different syntax and i want to kill myself. But let's skip the rant. This is part of my script anterior=`date +"%Y%0m" -d '1 month ago'` I basically need to get a past date in format 201002. Never mind the thing that, in the new environment, %0m means "no zeroes", while actually in the other one it means "yes, please put that zero on my string". It doesn't even accept the "1 month ago". I've read the man date for HP-UX and it seems you just can't do date arithmetic with it. I've been looking around for a while but all i find are lengthy solutions. I can't quite understand that such a typical administrative task like adding dates needs so much fuss. Isn't there a way to convert my one-liner to, well, i don't know, another one? Come on, i've seen proposed solutions that used bc, had thirty plus lines and magic number all over the script. The simplest solutions seem to use perl... but i don't know how to modify them, as they're quite arcane. Thanks!

    Read the article

1