日期:2014-05-20  浏览次数:20908 次

为什么提示没有MAIN方法?
package com.sl.java.jdbc;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import java.util.Vector;

//import com.sl.java.bean.Student;

public class Test {
private static Connection conn;
private Test(){

}
private static Test sdao=new Test(); 
public static Test getSdao(){
return sdao;
}
public static Vector<Connection> pool=new Vector<Connection>();
private static String driver;
private static String url;
private static String user;
  private static String password;
private static int current_num=0;
private static int MAX_SIZE = 100;
static{
Properties per=new Properties();
try{
per.load(Test.class.getResourceAsStream("pool.per"));
driver=per.getProperty("driver");
url=per.getProperty("url");
user=per.getProperty("user");
password=per.getProperty("password");
MAX_SIZE=Integer.parseInt(per.getProperty("MAX_SIZE"));
Class.forName(driver);
}catch(IOException e){
e.printStackTrace();
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
private void init(){
try{
for(int i=0;i<MAX_SIZE;i++){
pool.add(createConnection());
}
}catch(SQLException e){
e.printStackTrace();
}
}
private static Connection createConnection() throws SQLException {
conn=DriverManager.getConnection(url,user,password);
return conn;
}
public synchronized Connection getConnection() {

if (pool.size() == 0) {// 第一个用户
// CPU切换到另一个线程
init();
}
conn = pool.firstElement();
pool.removeElementAt(0);
current_num++;
System.out.println("当前连接数目为:"+current_num+",连接池对象为:"+pool.size());
return conn;
}
public void callback(Connection con) {
if (con != null) {
pool.add(con);
current_num--;
}
}
public void release() {
for (int i = 0; i < pool.size(); i++) {
pool.removeElementAt(0);
}
}
public static void main(String[] args){
sdao.getConnection();
}
}


------解决方案--------------------
你是如何执行的
------解决方案--------------------
肯定是没编译, 是在Eclipse集成开发环境吧 ? 看看你的JDK配置
------解决方案--------------------
配置下环境变量。用myeclipse偶尔会出现这种情况
------解决方案--------------------
配置下环境变量!
------解决方案--------------------
Eclipse会报java.lang.ExceptionInInitializerError,提示main线程有异常
------解决方案--------------------
应该是环境变量没有配置好,
------解决方案--------------------
应该是你的main函数中使用Test.class有问题。。。这里取不到。。。
per.load(Test.class.getResourceAsStream("pool.per"));