I have a variable in java which return type is Object(java.lang.Object). I want to store this variable value in MySQL database without casting in any other primitive data type. Is there any data type available in MySQL related to Object? Answer You can use a BLOB to store the raw data, but otherwise no, MySQL…
Tag: java
Alternatives to JSP for Spring MVC view layer [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed last year. The community revie…
log4j vs. System.out.println – logger advantages?
I’m using log4j for the first time in a project. A fellow programmer told me that using System.out.println is considered a bad style and that log4j is something like standard for logging matters nowadays. We do lots of JUnit testing – System.out stuff turns out to be harder to test. Therefore I be…
in which namespace / package to put exceptions?
What is the common or best practice to structure the location of your exception classes? Let’s say you have the packages/namespaces myproject.person (models and DAOs for persons) and myproject.order (models and DAOs for orders) and the exceptions PersonException and OrderException. Should I put the exce…
Create a triangle out of stars using only recursion
I need to to write a method that is called like printTriangle(5);. We need to create an iterative method and a recursive method (without ANY iteration). The output needs to look like this: This code works with the iterative but I can’t adapt it to be recursive. I should note that you cannot use any clas…
XML Schema to Java Classes with XJC
I am using xjc to generate Java classes from the XML schema and the following is an excerpt of the XSD. For the most part the generated classes are fine but for the above block I would get something like: with the following comment above it: I have placed a comment at the end of the two line in question.
Get Maven artifact version at runtime
I have noticed that in a Maven artifact’s JAR, the project.version attribute is included in two files: Is there a recommended way to read this version at runtime? Answer You should not need to access Maven-specific files to get the version information of any given library/class. You can simply use getCl…
Why would an Enum implement an Interface?
I just found out that Java allows enums to implement an interface. What would be a good use case for that? Answer Enums don’t just have to represent passive sets (e.g. colours). They can represent more complex objects with functionality, and so you’re then likely to want to add further functionali…
Turning a string into a Uri in Android
I have a string, ‘songchoice’. I want it to become a ‘Uri’ so I can use with MediaPlayer.create(context, Uri) How can I convert songchoice to the Uri? Answer Here’s the doc http://developer.android.com/reference/android/net/Uri.html#parse%28java.lang.String%29
How to ignore SSL certificate errors in Apache HttpClient 4.0
How do I bypass invalid SSL certificate errors with Apache HttpClient 4.0? Answer You need to create a SSLContext with your own TrustManager and create HTTPS scheme using this context. Here is the code,