Win a copy of Java by Comparison (eBook) this week in the Java in General forum!

Jonas Kazlauskas

Greenhorn
+ Follow
since Jun 19, 2014
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jonas Kazlauskas

OK, so I have some methods where queries are being executed AND some logic is being applied to the resultSet. I was advised to move my database logic out of the methods to make it easier to read and to make it less cluttered with lots of user interface code. So my question is, do I have to write a specific method containing database logic for every single method (cause queries differ)? Is it a good practice? Or shall I make database logic code more general to be used all over my program? But I don't want it to be too complex to read again... Here is my code.
Method containing database logic:


Method with ALL the database logic already out:
Thank you for your reply. This has solved my problem:
3 years ago
Hi there! I need your advice, coders! Please help!
The problem is that I populate the table with autoincrement primary key. I don't want it to be visible. I have been googling for hours to find no solution. It seems that sql/mysql provides no solution by selecting all table columns except one. So I wonder, how I could overcome this problem. Here is some of my code:

The ID is used in
I tried to omit ID from my SELECT statement, I tried to put Date as a first element in data[iEil][0] but neither options were successful. Data hasn't been changed in database. NOW, everything works fine, except I don't want ID column to be visible in my table. Any ideas?
3 years ago
Hi there,

I am completely lost. I am coding a program where I can track my finances. In one of the components(JLabel) I want to see money spent from fixed day of the month to this day. For example: the day of the month I want to be fixed is every 10th of the month, since today is 29th i want to be able to calculate a sum of money spent from today to 10th of this month if day of this month is > then 10th and from today to the 10th of last month if todays day of the month is < then 10th. Any ideas how can I construct my SQL query?
OK, it seems that I found the solution. I used BorderLayout for my JPanel; created JLabel and added it at the page end:
3 years ago
Hi there,

I am building a little application for personal use where I can track my finance. Now, what I would like to get is an always visible JTable "footer" OR horizontal space field attached to the bottom of the window. The idea is that scrolling down/up wouldn't affect it's visibility(like JTable header). Might a picture tell a thousand words: see attachment.
I am wondering, maybe JTable OR TableModel class has a property to solve this problem(I haven't found any)? Or shall I make another ScrollPane/JPanel? Any suggestions which path of search shall I pursue?
3 years ago
I understand it, ULF. On the other hand since I dont have
I think that my problem lies in my web.xml. So, once again, I dont want any buttons or imputlists. Here is my Birthdays.java code:


Here is my jsp code:


And finally, my web.xml:


Console logs:
Spa 28, 2014 11:31:52 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.8.0_20\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_20/bin/client;C:/Program Files/Java/jre1.8.0_20/bin;C:/Program Files/Java/jre1.8.0_20/lib/i386;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Vodafone\Vodafone Mobile Connect\Optimization Client\;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\Java\jdk1.8.0_20\bin;;D:\eclipse;;.
Spa 28, 2014 11:31:52 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:StudentsBirthdays' did not find a matching property.
Spa 28, 2014 11:31:52 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Spa 28, 2014 11:31:53 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Spa 28, 2014 11:31:53 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Spa 28, 2014 11:31:53 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Spa 28, 2014 11:31:53 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1172 ms
Spa 28, 2014 11:31:53 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Spa 28, 2014 11:31:53 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.12
Spa 28, 2014 11:31:53 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [350] milliseconds.
Spa 28, 2014 11:31:54 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Spa 28, 2014 11:31:54 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Spa 28, 2014 11:31:54 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1001 ms
statement prepared
element assigned
element assigned
statement prepared
element assigned
element assigned
statement prepared
element assigned
element assigned
statement prepared and so on until terminates..

Any ideas??
3 years ago
ULF, thank you. This is the right angle to solve my problem. I understand what you wrote and I am able to implement it in my code.
To answer your question - I wrote a few programs using JAVA+MySQL+servlet+jsp. But all the programs where using some input features(button, checkedlist..). And now I want to write a program that wouldnt need any input feature. User types url in browser - user sees data retrieved from DB. SO my question is - how to overcome this process of need to have a button. I tried to make this adjustment in my xml file


where servlet forwards request attribute to jsp but then I am getting an error(HTTP Status 500 - java.lang.NullPointerException) while trying to run it.
3 years ago
OK. I read your reference. I had read some pages(150) of Head First Servlets book before, some pages(150) of MySQLs anf Java developers guide. I thank you for your time BUT I still do NOT get it. I mean yes, I understand the good things MVC brings to the table: code reuse, clearness etc. I need a specific very basic solution down here. Can you share your knowledge please?
3 years ago
Hi guys,

I am learning how to program in JAVA servlet+MySQL. Decided to make a simple program where it shows who is celebrating birthday today by retrieving data from database. At the moment I managed to get it working by loading a form.html and pressing the button in it wich gets to the result.jsp and shows results there. My plan was to get a list of people who are celebrating there birthdays initially when the website is loaded/being loaded, I mean when you enter URL into your web browser and you get it instantly in browser. Is there a way to do it the way I want(JAVA+servlet+MySQL) instead of pressing a button/link?

Thank you for your time.
3 years ago
To tell you the truth, I didn't even notice that the text output was different ;) As advised, I did log checking and thats how I found a problem.


But strangely it didn't solve the problem straight away or I was too dumb to notice it. I changed my php file and then I got everything working properly.

I changed jpi-version = 7 instead of jpi-version=6 before. I wonder had this something to do with fix of second part of the problem(font changing)?
3 years ago
Hi there! I have an applet which I want to embed into HTML. In applet viewer in Eclipse IDE the view is this(see pict01), and when I access my index.php on local server I get this view(see pict02). I don't know what I am doing wrong. I checked it with Firefox, IE and chrome. No changes. Here is source code:


index.php:


I have these files in my local servers folder where I am trying to access it from(see pict03). Any ideas?
3 years ago
A minute after I submitted last post I figured out that it's not a casting issue but since you, Ulf, ar so great and fast in helping us - I didn't want to edit. The great news is that i got it running by (thanks to you) changing the layout

and


Now I need to play a bit with layout to make it look decent at least. I thank you very much for your help!
3 years ago
OK. After adding:


In console I get:
Label created javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,
maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,
horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=cats,verticalAlignment=CENTER,verticalTextPosition=CENTER]
Label created javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,
maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,
horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=cats,verticalAlignment=CENTER,verticalTextPosition=CENTER]
....

So I come to conclusion that the casting is the problem. I wonder if I can somehow extract "text" attribute or is it better to try to get back before I create an Array of Objects and try somehow to get my desired string from LinkedHashSet?
3 years ago
I don't get any exceptions or errors. Just the warnings I posted before. I removed "codebase" attribute and moved my jar file from archive dir to where my index.php and MyText.txt is. Still no good. Still getting the same view as in the picture I attached in my last post. I tried to change browsers - no effect. Looks like the file reading is done(see the picture).
Maybe the problem is in the bit of:?
3 years ago