Application 中没有 main() 函数。

解决方案 »

  1.   

    要放在main中,给个例子你参考吧!
    //这是使用JDBC驱动直接连接的驱动模式,
    import java.sql.*;
    class JDBCTest2 
    {
    public static void main(String[] args) 
    {
            String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
    String url = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=pubs";
    String user = "sa";
    String pwd = "2306";
    try
    {
    Class.forName(driver/*"com.microsoft.jdbc.sqlserver.SQLServerDriver"*/);
    Connection conn =DriverManager.getConnection(url,user,pwd/*"jdbc:microsoft:sqlserver://127.0.0.1:1433;User=xjl;Password=2306;DatabaseName=Shop"*/);
    System.out.println("数据库连接中....");
                Statement stmt =conn.createStatement();
    ResultSet results =stmt.executeQuery("select * from titles");
    //int num=1;
    while (results.next())
    {
    String titles =results.getString("title");
    String prices =results.getString("price");
    System.out.println("书名:"+titles+"   价格:"+prices);
    }
    stmt.close();
    conn.close();
    System.out.println("连接关闭中...");
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    }
    }
      

  2.   

    你是用什么编译的?
    如果有IDE应该是没这个问题的http://www.book23.com/ask13/ask182370.htm
    http://www.chinaunix.net/jh/26/128217.html你可以网上找找原因,你加个main函数看看,
    public static void main(String[] args) 
    {

    }