public class DateToString { public static void main(String[] args) { String date = "January 1, 2015"; SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat sdf2 = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH); try { String datechange = sdf1.format(sdf2.parse(date)); System.out.println(datechange); } catch (Exception e) { e.printStackTrace(); } } } 或者直接用下面代码:
String date = new SimpleDateFormat("yyyyMMdd").format(new SimpleDateFormat("MMMM d,yyyy",Locale.ENGLISH).parse("January 1, 2015"));
2. 向数据库插入带有单引号的字符串:
用两个单引号 ‘’ 来代替一个单引号 ’ ,将两个连续的单引号插入到数据库中后就变成了单引号,sqlserver使用两个单引号表示一个单引号的。
3. Bigint ,int, smallint
Bigint:从-2^63(-9223372036854775808) 到2^63-1(9223372036854775807)的整型数据(所有数字)。存储大小为8个字节。
Int:从-2^31 (-2,147,483,648)到2^31-1 (2,147,483,647)的整型数据(所有数字)。存储大小为4个字节。int的SQL-92同义字为integer。
Smallint:从-2^15(-32768) 到2^15-1 (32767)的整型数据。存储大小为2个字节。
Tinyint: 从0到255的整型数据。存储大小为一个字节。
注释:
在支持整数值的地方支持 bigint 数据类型。但是,bigint 用于某些特殊的情况,当整数值超过 int 数据类型支持的范围时,就可以采用 bigint。在SQL Server中,int数据类型是主要的整数数据类型。在数据类型优先次序表中,bigint位于smallmoney和int之间。只有当参数表达式是 bigint 数据类型时,函数才返回bigint。SQLServer不会自动将其它整数数据类型(tinyint、smallint和int)提升为bigint 。
4. Nvarchar在sqlserver中是可变。
如果将Url字段设置为nvarchar(100),虽然Url长度是可变的,但是如果插入的字符串长度超过100也是不可以的,nvarchar(100)意味着最长是100个字符。
5. Int型最大值是2亿多。
6. 没有为参数号 1 设置值。
很可能是因为复杂的字符串中含有单引号’,解决方法就是replaceAll(“’”,”’’”);就是用两个单引号替换掉单引号。
7. 标签 'https' 已声明。标签名称在查询批次或存储过程内部必须唯一。
同上。