Quick tips

Amarok’s playlist stop after play one music

Recently I had a problem like others Amarok’s 2.1.1 users: It play only one music and stop.

To resolve this: Close Amarok, delete the file ~/.kde/share/apps/amarok/current.xspf and then restart Amarok.

Least worked to me and I hope that works for you too! ;)

Until next!!


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!


How to enable Telnet and TFTP Client on Windows 7

Like in Windows Vista, Windows 7 don’t enable Telnet and TFTP Clients in installation.

To enable them, open Control Panel > Programs and Features > click Turn Windows features on or off in left side > enable Client Telnet  and  Client TFTP then click in OK.

I not tested in Windows Vista yet, but the process can be same.

See you soon!


The most used Unix commands for Windows

Have you thought about run commands like grep, chown, tail e su in Windows SO and can change command dir by ls?

Looking in internet for an alternative Win32 to command tail, I found UnixUtils. A compilation for Windows of most used commands in Linux/Unix.

You can download the ZIP file in SourceForge clicking here.

Bye!


Setting maximum number of characters in JTextField

The default implementation of JTextField not allow set maximum number of characters. To enable this resource you need implements a Document, overriding insertString method.

public class MaxLengthTextDocument extends PlainDocument {
	//Store maximum characters permitted
	private int maxChars;

	@Override
	public void insertString(int offs, String str, AttributeSet a)
			throws BadLocationException {
		if(str != null && (getLength() + str.length() < maxChars)){
			super.insertString(offs, str, a);
		}
	}

	//getter e setter omitted
}

Here we defined one class called MaxLengthTextDocument that extends PlainDocument. In insertString attribute, we checked if quantity of characters minor than maxChars attribute, inserting in String if true.

After this, only insert our implementation in JTextField, this way:

	...
	MaxLengthTextDocument maxLength = new MaxLengthTextDocument();
	maxLength.setMaxChars(50);//50 is a maximum number of character 

	jTextField.setDocument(maxLength);
	...

And voilà!

See ya!


  • AdSense

  • Copyright © 1996-2010 André L. S.. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress