DateFormat DOB = new SimpleDateFormat("yyyy-MM-dd");
String date ="\"1234-01-01\"";
java.sql.Date convertedDate=null;
try {
convertedDate = new java.sql.Date(DOB.parse(date.replaceAll("\"","")).getTime());
} catch (ParseException ex) {
ex.printStackTrace();
}
System.out.println(convertedDate);
Search This Blog
Popular Posts
-
Let say we have a String something like below. String sample="abc*123"; We want to split this String by '*'. We can...
-
sound -Convert matrix of signal data to sound Syntax sound(y,Fs) sound(y,Fs,bits) Description sound(y,Fs) sends audio signal y to the speak...
-
There are new phones will remove within next few weeks from sony. Sony xperia tipo, sony xperia tipo dual Sony xperia dual has dual sim...
-
When i try to configure mysql with CAS There were lots of problem occurred and i cannot find a good tutorials about this.I followed some tut...
-
PROBLEM 7 By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st pr...
-
This delete the file f1 File f1 = new File(file); boolean success = f1.delete(); if (!success){ System.out.println("Deleti...
-
PROBLEM The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. ANSWER 142913828...
-
In this post i will show you how to configure tomcat 7.x for SSL protocol in windows First we want to generate certificate file using jav...
-
samsung smart app challenge 2012 This contest offers $4.08 million in cash prizes and mega marketing support for app promotion to the to...
-
If you did not format your flash drive, then check whether the files are in hidden mode. Then follow these steps: Click on the link below ...
Followers
Friday, November 30, 2012
How to convert String to Java.sql.date and Java.sql.time
split a String by * in java
Let say we have a String something like below.
String sample="abc*123";
We want to split this String by '*'. We can't do this directly.Because in split the * has a special meaning.
This not working,
String spl[]=sample.split("*");
Therefore, we should use something like below.
String spl[]=sample.split("\\*");
String sample="abc*123";
We want to split this String by '*'. We can't do this directly.Because in split the * has a special meaning.
This not working,
String spl[]=sample.split("*");
Therefore, we should use something like below.
String spl[]=sample.split("\\*");
execute batch of queries in one time using java and JDBC
Let say we have something like below.
String [] queries = { "insert into employee (name, city, phone) values ('A', 'X', '123')", "insert into employee (name, city, phone) values ('B', 'Y', '234')", "insert into employee (name, city, phone) values ('C', 'Z', '345')",}; Connection connection = new getConnection();Statement statemenet = connection.createStatement(); for (String query : queries) { statemenet.execute(query); //execute query one by one}statemenet.close();connection.close(); Execute all the queries one by one.This is not a good practice.We can use something like below.Execute all the queries in once. Connection connection = new getConnection();Statement statemenet = connection.createStatement();for (String query : queries) { statemenet.addBatch(query);}statemenet.executeBatch();statemenet.close();connection.close(); As well as we can avoid sql injection by using something like below. String sql = "insert into employee (name, city, phone) values (?, ?, ?)";Connection connection = new getConnection();PreparedStatement ps = connection.prepareStatement(sql);final int batchSize = 1000;int count = 0;for (Employee employee: employees) { ps.setString(1, employee.getName()); ps.setString(2, employee.getCity()); ps.setString(3, employee.getPhone()); ps.addBatch(); if(++count % batchSize == 0) { ps.executeBatch(); }}ps.executeBatch(); // insert remaining recordsps.close();connection.close(); Tuesday, November 20, 2012
Files on flash drive changed to shortcuts fix
If you did not format your flash drive, then check whether the files are in hidden mode. Then follow these steps:
- Click on the link below and download the file "AutorunExterminator":
- Extract it: Double-click on "AutorunExterminator"
- Plug your pendrive now
- This will remove the autorun.inf files from your pendrive and also from the drives
- Click on Start > Run, type cmd and click OK
- Here it is assumed your pendrive letter is G (change as necessary)
- Enter this command.
attrib -h -r -s /s /d g:\*.*
- Press Enter
- Now check for your files in on the pen drive
- Now download the Malwarebytes' Anti-Malware from this link:http://en.kioskea.net/download/download-105-malwarebytes-anti-malware
- Update it and perform a "Full Scan"
- Note : The default selected option is "Quick Scan"
Thursday, November 8, 2012
Configure CAS SSO with mysql database
When i try to configure mysql with CAS There were lots of problem occurred and i cannot find a good tutorials about this.I followed some tutorials but i failed.Finally i found the way.So i decided to write a post about it.I explain this in localhost
Prerequest
Install mysql on the machine and be sure it's working properly.I used the default settings of mysql.If you used different one, change the configuration according to it.(localhost:3306)
Download apache tomcat and configure it to allow SSL connection.( You can follow my previous post)
Download cas server source code package
Install apache maven
How
<!-- change test as your database name, and give username and password of mysql login credential-->
<bean
id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost:3306/test?autoReconnect=true"
p:password=""
p:username="root" />
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
database.hibernate.dialect=org.hibernate.dialect.MySQLDialect
Prerequest
Install mysql on the machine and be sure it's working properly.I used the default settings of mysql.If you used different one, change the configuration according to it.(localhost:3306)
Download apache tomcat and configure it to allow SSL connection.( You can follow my previous post)
Download cas server source code package
Install apache maven
How
- Go to CAS source code location -> cas-server-webapp ->src->main->webapp->WEB-INF
- Open deployerConfigContext.xml in a text editor
- Change the bean serviceRegistryDao in deployerConfigContext.xml to something like this
<bean id="serviceRegistryDao" class="org.jasig.cas.services.JpaServiceRegistryDaoImpl"
p:entityManagerFactory-ref="entityManagerFactory" />
<!-- This is the EntityManagerFactory configuration for Hibernate -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="true"/>
<property name="showSql" value="true" />
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- change test as your database name, and give username and password of mysql login credential-->
<bean
id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost:3306/test?autoReconnect=true"
p:password=""
p:username="root" />
- Change following line
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
- Open cas.properties file
database.hibernate.dialect=org.hibernate.dialect.MySQLDialect
- Go to CAS source code location -> cas-server-webapp
- Open pom.xml and add following dependency according to your CAS version
<!--
Apache Commons DBCP
for Java 6 (use version 1.3 for Java 5 or lower)
-->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
<scope>runtime</scope>
</dependency>
<!--
Hibernate Core and Entity Manager
for CAS 3.5.0 and higher
-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<!--
Hibernate Entity Manager
for CAS 3.4.2.1
-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.5.0-CR-2</version>
</dependency>
<!--
MySQL Connector
-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.20</version>
</dependency>
Subscribe to:
Comments (Atom)