fady zohdy

Ranch Hand
+ Follow
since Jan 23, 2015
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
29
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by fady zohdy

Knute Snortum wrote:See this thread for more info.



thank you for you reply
but there was a one reply in this thread that discouraged the use of singletons and that they are harmful.
is this true? and if not do you think i should do it the same way as the one in this thread?
8 years ago
hello,
i am making a desktop application that connects to a mysql database on the same machine
the application has a class with the main method which takes you to a login screen then to the main frame which can take you to many other Jframes,
and in every frame i need to be connected to the database to query or update it.
i used to make a connection in every class but i heard that this is bad pactice so i was wondering if there is a way to have only an initial connection in the main class and then multiple statements throughout my application that rely on this connection!!!
8 years ago

Darryl Burke wrote:Are you sure tableValues isn't null?


it was null. i declared the arraylist but didn't initialize it. thank you
8 years ago
hello, i am trying to export data from a jtable to a pdf report but every time i try running the code it gives me this exception:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at GUI.QC_receiving_book.printButtonActionPerformed(QC_receiving_book.java:309)
at GUI.QC_receiving_book.access$600(QC_receiving_book.java:26)
at GUI.QC_receiving_book$7.actionPerformed(QC_receiving_book.java:165)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6516)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6281)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4872)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:740)
at java.awt.EventQueue.access$300(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:699)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:713)
at java.awt.EventQueue$4.run(EventQueue.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:710)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

i tried avoiding the null exception by using the if statement but it didn't work.
the row i choose from the table is full meaning there are no empty attributes. and all the data are imported from a mysql database to the table as String so there can't be any casting errors.
this is the part of the source code with the problem and i will also post the printing method.
i tried debugging the class and when stepping into the first if statement it opened the jTable.java file and pointed at the getSelectedRow() method and this sentence "variable information not available.source compiled without -g option"
sorry about the long exception but i just did copy/paste.

8 years ago

Jesper de Jong wrote:
Note that Date objects do not have a format by themselves. If you are getting the results as Date objects, then they will just contain the date value - without any format.
[/code]


it worked. thanks.
i did use the Date class but i thought the date_format() function will format the date before passing it to the Date object. it seems i miss understood.
i am trying to get the manufacturing date and expiry date in the dd-mm-yyyy format using the date_format() function in mySQL but it keeps giving me this format sat mar 28 00:00:00 EET 2015.
the manufacturing_date and expiry_date columns in the mysql table are set to date value.
i used the str_to_date(d,'%d-%m-%Y') function when inserting the value into the table.
and i tried the date_format() function in the command prompt and it gave me the desired output!!!
can anybody help me please?

Paul Clapham wrote:You didn't double-check the URL syntax enough... there's no "dbms" in it. Check again.


i am sorry. you were right . thanl you so much. it is supposed to be jdbc
9 years ago

Paul Clapham wrote:You didn't double-check the URL syntax enough... there's no "dbms" in it. Check again.



:D what do you mean there is no dbms? i am sure it's there. is it supposed to be in another format or something?
9 years ago
hello
i have been stuck in this problem for two days now and i don't seem to find a solution for it.
i started learning mysql to connect my program to a database but every time i try to connect i get this error.
java.sql.SQLException: No suitable driver found for dbms:mysql://localhost:3306/apexdemo
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at JDBCdemo2.main(JDBCdemo2.java:7)

i did the following: - added the mysql-connector-java-5.1.34 jar to my classpath
- added mysql jdbc driver to the project library
- double checked the url syntax and spelling errors
- checked that the server is running

9 years ago

Campbell Ritchie wrote:If you are entering 4 values from the keyboard you need a 4‑element array to hold those 4 values. You are setting the length of the array to a different amount, to be requested from the keyboard. I shall leave you to decide the best way to sort that problem out.



thanks man. you are awesome.
9 years ago

Henry Wong wrote:
Well, assuming that this line is close, it would be caused by this line...

which can be caused by two possibilities. However, from the code, we can eliminate one.

It is most likely that your input doesn't split to four components -- in fact, from the error message, it only splits to one element.

Henry


you are right. this line is the cause and the input does split to one element(the first one).
this is my input separated by blank spaces: 40 80 90 50
how do i split it to four components?
and thanks for the help
9 years ago

Henry Wong wrote:

Can you show us which is line 23 of your program? We don't know if you show us everything -- actually, you didn't since we know your class is in a package, so, we don't know which is line 23.

Henry



i am really sorry . i modified in the code before submitting it here. here is the right exception

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at testing.Arrays.main(Arrays.java:19)
9 years ago
i found this assignment where i am supposed to get scores input then grade the students according to their scores but i am getting this exception:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at testing.Arrays.main(Arrays.java:23)
9 years ago

S Majumder wrote:Completely agree with Stefan ..
One quick question
Why you declared 3 inner classes ?
Satya


first of all,thank you for your reply
the first two were comparator classes that are used to sort my list in a specific way.
the third one i put there because i was just in a hurry and wanted to test the code.i know i should have put that one in a separate class
9 years ago

Stefan Evans wrote:
A good habit to get into in a constructor is to assign variables with:
this.name = name. That way there is no confusion about which value you are setting and which is being set from.


got it working.thank you
9 years ago