java

How to use JCache in Scala? I get compiler type error: found String required K

I'm learning Scala and trying to use javax.cache in Scala code and can't find how to solve this problem: val cacheFactory = CacheManager.getInstance.getCacheFactory val map = new HashMap val cache = cacheFactory.createCache(map) def rawSet(key:String, value:Array[Byte]) { cache.put(key, value) } and the compiler error is: er...

Spring + Hibernate = Unknown entity

I'm trying to combine Spring with Hibernate using Annotations and I'm getting the following error: org.springframework.orm.hibernate3.HibernateSystemException : Unknown entity: entities.Bar; nested exception is org.hibernate.MappingException: Unknown entity: entities.Bar Here is my setup... My Entity: package entities; @Entity ...

Parameterized Query: Check if field is in array of values in SELECT statement

I'm trying to configure a parameterized query to the effect of: SELECT field1 FROM myTable WHERE field2 IN (1,2,3,4) The database I'm using is Postgres. This query run successfully unparameterized, but I'd like to use a parameterized query with a JdbcTemplate to fill in the list for valid field2 values (which are integers). Trying v...

Hibernate Question on Sessions

Hi, I am writing a web application that allows a user to get an employee's personal information and edit it (email, phone, name, etc). When I deploy the application on the server, if I try edit the employee, I can occasionally get an error saying "Hibernate session is already closed." My code for talking to the database via hibernate is...

How to store data into MySQL database?

I have created a java application which stores data into MySQL database. For that I have done the following things: I have installed MySQL database on my computer. I have created a database on that MySQL server. I have created a table in the database with the required schema. Now I want to deliver this application to various clients...

Displaying jpg image on JPanel

How can I display jpg image which I stored in arraylist in JPanel? Im not able to display the jpg files in the JPanel. String[] pictureFile = {"A.jpg","B.jpg","C.jpg"}; List<String> picList1 = Arrays.asList(pictureFile); Collections.shuffle(picList1); ImageIcon icon = new ImageIcon("picList1.get(0)"); JLabel label1 = new JLabel(...

How Can I rewrite SEO friendly URL on STRUTS?

Hi We have a website which is coded Java with Struts Framework. The WebSite's Urls are not seo friendly. All of them are like below ../buyerApplication.do&companyId=2323 Now We want to make these URLs SEO friendly and I searched and found these solutions: tuckey.org/urlrewrite : but i don't rely on this system. adding title end o...

How can I check if multiplying two numbers in Java will cause an overflow?

I want to handle the special case where multiplying two numbers together causes an overflow. The code looks something like this: int a = 20; long b = 30; // if a or b are big enough, this result will silently overflow long c = a * b; That's a simplified version - in the real app, a and b are sourced elsewhere at runtime. What I want ...

How should I throw a divide by zero exception in Java without actually dividing by zero?

I have an I2C device that wants two inputs: a denominator and a numerator. Both are written to separate addresses, so no actual calculation (numerator/denominator) is done. The problem with this is that a divide by zero could occur on the I2C device, so a divide by zero error needs to be checked for. Ideally, exactly the same thing would...

My .jar file is not working in java

I have created an application and it is working correctly when I am executing it through NETBEANS. After that I had clicked on "Clean and Build" to build a SiteScrapper.jar file. Now when I am executing it through command prompt by invoking the following dos command: java -jar "SiteScrapper.jar" I am getting the following exception ...

Subsampling image when reading using JAI

Hi, An application I have reads in quite large images (jpegs) but only needs to work with smaller images so I subsample them with something like ImageReadParam param = reader.getDefaultReadParam(); param.setSourceSubsampling(4, 4, 0, 0); img = reader.read(0); However, due to a bug in the jpeg reader that does not handle some meta dat...

Use NamedParameterJdbcTemplate to update array field

I have a double precision array field dblArrayFld in a table myTable and I'd like to update it using Spring's NamedParameterJdbcTemplate (I'm using Postgres). I'm running code like this: SqlParameterSource params = (new MapSqlParameterSource()) .addValue("myarray", myDblArrayListVar) .addValue("myid", 123); namedJdbcTemplate.updat...

Is there some place on the internet where I can run my Java program?

A program I am working on takes forever to complete (~3days, everytime). Is there some place on the internet where I can leave the code, some robot might run it for me and I can come back and collect the results? Some online judge that offers this capability? [I am not talking abt optimisations here.] ...

Java Swing: Read many images files without memory problems?

Hi, I'm writing a Java Swing application that will load from disk about 1500 png images that range in size from 50kb to 75kb each. I don't need to load all of them at once, but I will need to load at 50 images at a time. I've been trying to load them using the typical: new javax.swing.ImageIcon(getClass().getResource("myimage.jpeg") ...

Adding an image to a JTooltip without knowing the image's path (due to the image being a temporary ressource)

To be a little more specific: I've built a simple multithreaded TCPServer (Java) which communicates with clients (C# / mono). On request the Clients take a screenshot and send it to the Server. The screenshots are then displayed in a JTable. I'd like to add a tooltip to these images in the table with the same image but in another size. T...

JBoss JMS provider

I need to write a Message Driven Bean. I'm using JBoss IDE 1.5. I understand the concept behind MDB's but I don't really know how to install the JMS provider (JBoss MQ? I think) and use it so that it will be used to broker my message to an MDB. does anyone know of a tutorial I can use ? ...

Regular expression, replace all commas between double quotes

I have this string: 1001,"Fitzsimmons, Des Marteau, Beale and Nunn",109,"George","COD","Standard",,109,8/14/1998 8:50:02 What regular expression would I use to replace the commas in the "Fitzsimmons, Des Marteau, Beale and Nunn" with a pipe | so it is: "Fitzsimmons| Des Marteau| Beale and Nunn" Should have clarified, I am doing a s...

Connecting Widgets

Hello, My project is about drawing ER Diagrams, for this I am using GWT. For now i have most of the frontend working. Now I want to have lines connecting two widgets to create a relationship between the entities and attributes. For that I want to create 4 corner points to which the lines can connect (Technology something similar to EDra...

java Vector and thread safety

I'm wondering if this code will do any trouble: I have a vector that is shared among many threads. Every time a thread has to add/remove stuff from the vector I do it under a synchronized block. However, the main thread has a call: System.out.println("the vector's size: "+ vec.size()); which isn't synchronized. Should this cause tro...

How do I make a Class extend Observable when it has extended another class too?

I am learning java and i want to make my class into an observable class. However I already have it extending another class. What do I do? ...