April 27th, 2009 in Uncategorized | No Comments »
Changing column size in both MySQL and MS SQL Server. When changing from wider to narrower size data might be truncated so be aware of that.
MySQL
ALTER TABLE workbook MODIFY NAME varchar(255)
MS SQL
ALTER TABLE workbook
ALTER COLUMN [NAME] VARCHAR(255) NULL
GO
Columns that part of primary key can’t be altered.
April 16th, 2009 in Uncategorized | No Comments »
Exactly what the title says, this snippet will fire all job for all schedulers registered.
// Get our scheduler factory
StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
Collection<Scheduler> schedulers=schedulerFactory.getAllSchedulers();
for(Scheduler scheduler:schedulers){
System.out.println("scheduler "+scheduler.getSchedulerName());
String[] groups=scheduler.getJobGroupNames();
for(String jobGroup:groups){
System.out.println(" ** GROUP="+jobGroup);
String[] jobNames=scheduler.getJobNames(jobGroup);
for(String jobName:jobNames){
System.out.println(" ** jobName="+jobName);
//Fire actuall job
scheduler.triggerJob(jobName, jobGroup);
}
}
}
April 13th, 2009 in Uncategorized | No Comments »
Sometime we need to provide one script that works on multiple server, here is how to do in for SQL Servers 2000 and 2005.
We will use simple technique to detect the server type using the serverproperty('ProductVersion') for a list of options visit
SERVERPROPERTY (Transact-SQL). So lets see what are the pros and cons
of this technique.
Pros
This technique allows us to use either SQL 2000 or 2005 servers.
Cons
Cant’ just use new sql 2005 syntax since 2000 does not recognize it, so we are executing it with exec after the new code string have bean concatenated.
This could easily leave us open to sql injection if we are not sanitizing the input correctly in web environment.
Another approach would be to execute a script file with the osql or sqlcmd
EXEC master..xp_cmdshell 'OSQL -S devserver -U sa -P pass -ic:\script2000.sql -n'
EXEC master..xp_cmdshell 'SQLCMD -S devserver -U sa -P pass -ic:\script2005.sql'
Complete Example
DECLARE @sql2005Code varchar(255)
SET @sql2005Code = 'print ''SQL 2005 Code'' '
DECLARE @ver nvarchar(128)
SET @ver = CAST(serverproperty('ProductVersion') AS nvarchar)
SET @ver = SUBSTRING(@ver, 1, CHARINDEX('.', @ver) - 1)
-- SQL 2000
IF ( @ver = '8' ) BEGIN
print 'SQL 2000'
END
-- SQL 2005
ELSE IF ( @ver = '9' )BEGIN
exec (@sql2005Code)
END
April 8th, 2009 in Uncategorized | No Comments »
While converting from Ant to Maven2 i have came across following error while trying to compile the project
generics are not supported in -source 1.4
(try -source 1.5 to enable generics)
private Map variables;
To fix the problem we need to add the pluggin configuration to our pom.xml
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
Thats it.