Hi all, i have to choose a database for a big desktop application.
Which of this db is better: Firebird, JavaDB, hsqldb ?
I need perfomance and easy to use, and totally free license.
Thank.
I just had a little surprise in a Webapp, where I'm using EL in .jsp pages.
I added a boolean property and scratched my head because I had named a boolean "isDynamic", so I could write this:
<c:if test="${page.isDynamic}">
...
</c:if>
Which I find easier to read than:
<c:if test="${page.dynamic}">
...
</c:if>
However the .jsp failed to compile, with the error:
javax.el.PropertyNotFoundException: Property 'isDynamic' not found on type com...
I turns out my IDE (and it took me some time to notice it), when generating the getter, had generated a method called:
isDynamic()
instead of:
getIsDynamic()
Once I manually replaced isDynamic() by getIsDynamic() everything was working fine.
So I've got really two questions here:
is it bad to start a boolean property's name with "is"?
wether it is bad or not, didn't IntelliJ made a mistake here by auto-generating a method named isDynamic instead of getIsDynamic?
hey everybody,
I have a jsp page which contains the code which prints all files in a given directory and their file paths. The code is
if (dir.isDirectory())
{
File[] dirs = dir.listFiles();
for (File f : dirs)
{
if (f.isDirectory() && !f.isHidden())
{
File files[] = f.listFiles();
for (File d : files)
{
if (d.isFile() && !d.isHidden())
{
System.out.println(d.getName()+
d.getParent() + (d.length()/1024));
}
}
}
if (f.isFile() && !f.isHidden())
{
System.out.println(f.getName()+
f.getParent() + (f.length()/1024));
}
}
}
The problem is that it prints the complete file path, which when accessed from tomcat is invalid. For example, the code spits out the following path:
/usr/local/tomcat/sites/web_tech/images/scores/blah.jpg
and I want it to only print the path up to /images ie
/images/scores/blah.jpg
I know I could just mess around with an actual string, ie splitting it or string matching, but is there an easier way to do it?
Thanks
Hi,
I'm having a problem with image scaling. When I use the following code to scale an image it ends up with a line either at the bottom or on the right side of the image.
double scale = 1;
if (scaleHeight >= scaleWidth) {
scale = scaleWidth;
} else {
scale = scaleHeight;
}
AffineTransform af = new AffineTransform();
af.scale(scale, scale);
AffineTransformOp operation = new AffineTransformOp(af, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
BufferedImage bufferedThumb = operation.filter(img, null);
The original image is here: http://tinyurl.com/yzv6r7h
The scaled image: http://tinyurl.com/yk6e8ga
Does anyone know why the line appears?
Thanks!
Hello, i have an application with use Hibernate and Mysql. In Mysql i have a blob in my table.
When i record a value in this table with accent like é or è in mysql i have a good result (binary) so when i want read into my jsp i have ? instead of é
I'm am trying to upload a file into mainframe server using FTP. My code is below
FTPClient client = new FTPClient();
InputStream in = null;
FileInputStream fis = null;
try{
client.connect("10.10.23.23");
client.login("user1", "pass123");
client.setFileType(FTPClient.BINARY_FILE_TYPE);
int reply ;
reply = client.getReplyCode();
System.out.println("Reply Code:"+reply);
if(FTPReply.isPositiveCompletion(reply)){
System.out.println("Positive reply");
String filename ="D:\\FILE.txt";
in = new FileInputStream(filename);
client.storeFile("FILE.TXT", in);
client.logout();
fis.close();
}else{
System.out.println("Negative reply");
}
}catch(final Throwable t){
t.printStackTrace();
}
The code gets struck in client.storeFile("FILE.TXT", in);
I am unable to debug. Please suggest ways / solutions.
In a lot of real life implementations of applications we face the requirement to import some kind of (text) files. Usually we would implement some (hardcoded?) logic to validate the file (eg. proper header, proper number of delimiters, proper date/time value,etc.). Eventually also need to check for the existence of related data in a table (eg. value of field 1 in text file must have an entry in some basic data table).
While XML solves this (to some extend) with XSD and DTD, we end up hacking this again and again for proprietary text file formats.
Is there any library or framework that allows the creation of templates similar to the xsd approach ? This would make it way more flexible to react on file format changes or implement new formats.
Thanks for any hints
Sven
I like to replace a certain set of characters of a string with a corresponding replacement character in an efficent way.
For example:
String sourceCharacters = "šdccŠÐCCžŽ";
String targetCharacters = "sdccSDCCzZ";
String result = replaceChars("Gracišce", sourceCharacters , targetCharacters );
Assert.equals(result,"Gracisce") == true;
Is there are more efficient way than to use the replaceAll method of the String class?
My first idea was:
final String s = "Gracišce";
String sourceCharacters = "šdccŠÐCCžŽ";
String targetCharacters = "sdccSDCCzZ";
// preparation
final char[] sourceString = s.toCharArray();
final char result[] = new char[sourceString.length];
final char[] targetCharactersArray = targetCharacters.toCharArray();
// main work
for(int i=0,l=sourceString.length;i<l;++i)
{
final int pos = sourceCharacters.indexOf(sourceString[i]);
result[i] = pos!=-1 ? targetCharactersArray[pos] : sourceString[i];
}
// result
String resultString = new String(result);
Any ideas?
Btw, the UTF-8 characters are causing the trouble, with US_ASCII it works fine.
I have two final classes that are used in my unit test. I am trying to use whenNew on the constructor of a final class, but I see that it calls the actual constructor.
The code is
@PrepareForTest({A.class, B.class, Provider.class})
@Test
public void testGetStatus() throws Exception {
B b = mock(B.class);
when(b.getStatus()).thenReturn(1);
whenNew(B.class).withArguments(anyString()).thenReturn(b);
Provider p = new Provider();
int val = p.getStatus();
assertTrue((val == 1));
}
public class Provider {
public int getStatus() {
B b = new B("test");
return b.getStatus();
}
}
public final class A {
private void init() {
// ...do soemthing
}
private static A a;
private A() {
}
public static A getInstance() {
if (a == null) {
a = new A();
a.init();
}
return a;
}
}
public final class B {
public B() {
}
public B(String s) {
this(A.getInstance(), s);
}
public B(A a, String s) {
}
public int getStatus() {
return 0;
}
}
On debug, I find that its the actual class B instance created and not the mock instance that is returned for new usage and assertion fails.
Any pointers on how to get this working.
Thanks
Given an arbitrary set of letters
String range = "0123456789abcdefghijklmnopABCD#";
I am looking for 2 methods to encode/decode from long <- String
String s = encode( range, l );
and
long l = decode( range, s );
So decode(range, encode(range, 123456789L)) == 123456789L
And if range is "0123456789" thats the usual way of encoding.
I have following problem,
Code:
String a="Yeahh, I have no a idea what's happening now!";
System.out.println(a);
a=a.replaceAll("a", "");
System.out.println(a);
Before removing 'a', result:
Yeahh, I have no a idea what's happening now!
Actual Result:
After removing 'a', result:
Yehh, I hve no ide wht's hppening now!
Desired Result:
Yeahh, I have no idea what's happening now!
Anyone can gimme some advices to achieve my desired result?
I need to download a pdf file from a webserver to my pc and save it locally.
I used Httpclient to connect to webserver and get the content body:
HttpEntity entity=response.getEntity();
InputStream in=entity.getContent();
String stream = CharStreams.toString(new InputStreamReader(in));
int size=stream.length();
System.out.println("stringa html page LENGTH:"+stream.length());
System.out.println(stream);
SaveToFile(stream);
Then i save content in a file:
//check CRLF (i don't know if i need to to this)
String[] fix=stream.split("\r\n");
File file=new File("C:\\Users\\augusto\\Desktop\\progetti web\\test\\test2.pdf");
PrintWriter out = new PrintWriter(new FileWriter(file));
for (int i = 0; i < fix.length; i++) {
out.print(fix[i]);
out.print("\n");
}
out.close();
I also tried to save a String content to file directly:
OutputStream out=new FileOutputStream("pathPdfFile");
out.write(stream.getBytes());
out.close();
But the result is always the same: I can open pdf file but i can see white pages only. Does the mistake is around pdf stream and endstream charset encoding? Does pdf content between stream and endStream need to be manipulate in some others way?
Hello guys,
I want to make a database that will hold a date in it(SQLite).
Now first to ask is what is the right syntax to declare a date column.
The second i want to know is how to insert date in it after that.
And the third thing i want to know is how to select dates between, for example to select all rows which contain date between 01/05/2010 and 05/06/2010.
Thank you
Is there a utility to get a property which isnt prefixed by get from an object using reflection similar to BeanUtils? e.g. if I specify "hashcode" and I want to get the object.hashcode() value.
Thanks.
int[] arrc = new int[] {1, 2, 3};
System.out.println(new ArrayList(Arrays.asList(arrc)));
prints address, but i desire to use toString as in ArrayList.
Is it possible ?
I'm looking for a log viewer with similar capablilties as Chainsaw, in which I can tail Glassfish log files over for instance SSH/SCP. Does anyone know if such a tool exist?
I am trying to load properties from a file (test.properties)
The code I use is as follows:
URL url = getClass().getResource("../resources/test.properties");
properties.load(url.openStream());
But when executing the second line I get a NPE. (null pointer exception)
I'm not sure what's wrong here... I have checked that the file exists at the location where URL points to...
Any help is appreciated....
Between the transitions of the web app I use a Session object to save my objects in.
I've heard there's a program called memcached but there's no compiled version of it on the site,
besides some people think there are real disadvantages of it.
Now I wanna ask you.
What are alternatives, pros and cons of different approaches?
Is memcached painpul for sysadmins to install? Is it difficult to embed it to the existing infrastructure from the perspective of a sysadmin?
What about using a database to hold temporary data between web app transitions?
Is it a normal practice?
I executed the below code in Eclipse, but the GOTO statements in it is not effective. How to use it?
case 2:
**outsideloops:**
System.out.println("Enter the marks (in 100):");
System.out.println("Subject 1:");
float sub1=Float.parseFloat(br.readLine());
**if(sub1<=101)
goto outsideloops;**
System.out.println("Subject 2:");
float sub2=Float.parseFloat(br.readLine());
System.out.println("Subject 3:");
float sub3=Float.parseFloat(br.readLine());
System.out.println("The Student is "+stu.average(sub1,sub2,sub3)+ "in the examinations");
break;
I am trying to benchmark some code. I am sending a String msg over sockets. I want to send 100KB, 2MB, and 10MB String variables. Is there an easy way to create a variable of these sizes?
Currently I am doing this.
private static String createDataSize(int msgSize) {
String data = "a";
while(data.length() < (msgSize*1024)-6) {
data += "a";
}
return data;
}
But this takes a very long time. Is there a better way?
Applet Communication:
write a small applet and embed it in html-file with following functionality.
1. change applet bg color by receiving a javascript command with the color parameter.
2. show dynamic mouse position in applet-window and display position in html-site. use live-connect between applet and browser communication.
So I have my main class here, where basically creates a new jframe and adds a world object to it. The world object is basically where all drawing and keylistening would take place...
public class Blobs extends JFrame{
public Blobs() {
super("Blobs :) - By Chris Tanaka");
setVisible(true);
setResizable(false);
setSize(1000, 1000);
setIgnoreRepaint(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
add(new World());
}
public static void main(String[] args) {
new Blobs();
}
}
How exactly would you get key input from the world class?
(So far I have my world class extending a jpanel and implementing a keylistener. In the constructor i addKeyListener(this). I also have these methods since they are auto implemented:
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_W)
System.out.println("Hi");
}
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {}
However this does not seem to work?
Is there any way to enable horizontal scrollbar whenever necessary??
The situation was as such:
I've a JTable on Netbeans, one of the cells, stored a long length of data. Hence, I need to have horizontal scrollbar. Anyone has idea on this?
THanks in advance for any helps..
Hi,
I have a spring action that I am rendering some json from the controller, at the minute its returning the content type 'text/plain;charset=ISO-8859-1'.
How can I change this to be 'application/json'?
Thanks
Jon