Solving problems with removal of the external HD in Windows 7
Some times I had problems when disconnected my external HD using Windows' s Removal Device Assistant, the most frequently was "This device is currently in use. Close any programs or windows that...". This message appeared even with all programs closed.
After checked Windows settings, process and services, I noticed that the problem was in service "Windows Media Player Network Sharing Service", forcing me to stop it before remove the device.
But still, this solution not is right, then I found the most right:
The service "Windows Media Player Network Sharing Service" is responsible to share your media files (musics and videos) in your network or in the internet (like your name sounded.
). This is default setting in Windows 7, to disable it...
Click in Start menu, type "Network and sharing center" and select the application. Like show in the image
Click "Choose homegroup and sharing options"

Clique na opção "Escolher opções de grupo doméstico e de compartilhamento"

Now click on "Choose media streaming options..."

Change option of item "Media programs on this PC and remote conections..." to "Blocked".

Finish! From now you can remove your external hard drive or other removable storage devices without problems.
Setting up internet access through proxy server
Today I had a trouble in my workplace when a client application, running through a terminal (DOS prompt), not reach the server hosted in the internet, this is because the company where I work use proxy.
After some tries I found two solutions to solve my access problem: first was pass as Java parameters the proxy's configurations.
$ java -Dhttp.proxyHost=serv -Dhttp.proxyPort=port -Dhttp.proxyUser=user -Dhttp.proxyPassword=pass ClassJava
-Dhttp.proxyHost = IP or host name of server proxy
-Dhttp.proxyPort = Proxy port
-Dhttp.proxyUser = User
-Dhttp.proxyPassword = Password
This way the class ClassJava will have access to internet through proxy server.
Another way, was insert the settings in own class:
public static void main(String[] args){
...
System.getProperties().put("proxySet", "true");
System.getProperties().put("http.proxyHost", "serv");
System.getProperties().put("http.proxyPort", "port");
System.getProperties().put("http.proxyUser", "user");
System.getProperties().put("http.proxyPassword", "password");
...
}
proxySet = Connect, or not, through proxy server
http.proxyHost = IP or host name of server proxy
http.proxyPortt = Proxy port
http.proxyUse = User
http.proxyPassword = Password
Using this resource you can set your application to access the internet through proxy server.
I hope help you. Bye!
Creating transparent and shaped windows using Java Swing/AWT
The Java AWT offer various possibilities about window manipulation. Today I'll talk about two possibilities using class AWTUtilities.
Building a transparent window
To make a Window (JFrame, JDialog ...) with alpha effect, you should invoke the method AWTUtilities.setWindowOpacity. This method parameters are: the window to apply transparency and transparency degree, that can be between 0 (zero) and 1, being 0 invisible and 1 totally visible.
JFrame window = new JFrame("My Window");
//70% of transparency
AWTUtilities.setWindowOpacity(window, .7f);
window.setSize(800,600);
window.setVisible(true);
Changing window shape
To change the window shape you should use the method AWTUtilities.setWindowShape. This method parameters are: window that will be changed and the new shape (java.awt.Shape) of the window.
The most efficiently form to use is to implement the method componentResized(), cause you may recompute the window and components size
Here I'll use a triangle with 70% of transparency.
final JFrame window = new JFrame("My Window");
try {
//Add the ComponentListener to implement componentResized method
window.addComponentListener(new ComponentAdapter(){
@Override
//building componentResized
public void componentResized(ComponentEvent e) {
int[] x = {0,400,800}; //Pontos X do polígono
int[] y = {600,0,600}; //Pontos Y do polígono
//Triangle with 800 w x 600 h
Shape shape = new Polygon(x, y, 3);
AWTUtilities.setWindowShape(window, shape);
//70% of transparency
AWTUtilities.setWindowOpacity(window, 0.7f);
}
});
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
window.setUndecorated(true); //removing title bar
window.setSize(800,600);
window.setVisible(true);
Notice that the method setUndecorated( ) was invoked with true as value. This method are responsible by hide the title bar (one with icon and the maximize, minimize and close buttons). This is really necessary, because with title bar visible the window are not be shaped.
I hope you enjoy...
Saving files in BLOB table column of a data base
To insert a file, is it in any format, you need call the method setBinaryStream, implemented by PreparedStatement.
PreparedStatemente.setBinaryStream(int index, Inputstream is, int length);
In sample, we set a table called FILEthat contains BLOB column called BIN.
//Normal connection, as any JDBC connection
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@<IP>:<PORT>:<SID>","<USER>","<PASSWORD>");
//Reading the file and retrieving an InputStream
File file= new File("<COMPLETE_FILE_PATH>");
FileInputStream fis = new FileInputStream(file);
//Preparing statement
PreparedStatement ps = conn.prepareStatement("INSERT INTO FILE(bin) VALUES(?)");
//Passing InputStream and file length
ps.setBinaryStream(1, fis, (int)file.length());
ps.execute();
ps.close();
conn.close();
I used Oracle 8i to execute this sample. I haven't a MySQL/PostgreSQL/MS SQL Server in my dispose, then you'll responsible for testing in this data bases and send me the results, OK
Thanks! Until next time!


