代码1(正确)
package com.it.util;
import java.sql.Connection;
import java.sql.PreparedStatement;
import org.junit.Test;
public class TestCRUD {
@Test
public void test1(){
Connection conn = null;//有效
PreparedStatement ps = null;//有效
conn = C3P0Util.getConnection();//有效
System.out.println(conn.getClass().getName());//有效
}
}
代码2(错误)
package com.it.util;
import java.sql.Connection;
import java.sql.PreparedStatement;
import org.junit.Test;
public class TestCRUD {
@Test
public static void test1(){
Connection conn = null;//有效
PreparedStatement ps = null;//有效
conn = C3P0Util.getConnection();//有效
System.out.println(conn.getClass().getName());//有效
}
}
原因:代码差不多,死活运行不起来,就应为 方法上面加了一个static