1.使用反射列出类的所有方法
//Obtain the Class instance
Class personClass = Person.class;
//Get the methods
Method[] methods = personClass.getDeclaredMethods();
//Loop through the methods and print out their names
for (Method method : methods) {
System.out.println(method.getName());
}
2.连接MySQL数据库
Class.forName(“com.mysql.jdbc.Driver”);
connection=
DriverManager.getConnection("jdbc:mysql://localhost:3306/class3","root","123456");
3.Mysql数据库中的字段长度是指字节还是字符?
字段长度长度是当前字符集的字符长度,而不是字节长度!
3.try catch finally执行顺序
1、finally语句总会执行
2、如果try、catch中有return语句,finally中没有return,那么在finally中修改除包装类型和静态变量、全局变量以外的数据都不会对try、catch中返回的变量有任何的影响(包装类型、静态变量会改变、全局变量)
3、尽量不要在finally中使用return语句,如果使用的话,会忽略try、catch中的返回语句,也会忽略try、catch中的异常,屏蔽了错误的发生
4、finally中避免再次抛出异常,一旦finally中发生异常,代码执行将会抛出finally中的异常信息,try、catch中的异常将被忽略