import java.sql.*;
import java.awt.*;
class Jdbcesp{
public static void main(String[] agrs[])throws Exception{
String ul="jdbc:odbc:www";
Connection con=null;
Statement sm=null;
ResultSet rs=null;
try{
//加载驱动程序
Class.forName("sum.jdbc.odbc.JdbcOdbcDriver");
}catch(Exception e){
  System.out.println("无法连接 JDBC-ODBC Brideg 驱动程序");
  return;
}
  //与数据库见你连接并显示
try{
con=DriverManager.getConnection(ul);
sm=con.createStatement();//创建对象
//执行SQL语句并显示
rs=sm.executeQuery("select xtype,status from systypes where name='bigint'");
System.out.println("结果为:");
while(rs.next()){
//取名字段的值
int xtype=rs.getInt(1);
int status=rs.getInt(1);
System.out.println("xtype"+xtype);
System.out.println("status"+status);
}
}catch(SQLException e){}
finally{
try{
//关闭对象
rs.close();
sm.close();
//关闭连接
con.close();
}catch(SQLException e){
e.printStackTrace();
}
}  
}
}这个程序在编译的过程中:
javac Jdbcesp.java  后通过了~
java Jdbcesp  就显示这样的一个错误~~
Exception in thread "main" java.lang.NosuchMethodError:main

解决方案 »

  1.   

    你都没有说要连接哪个数据库!用户名密码什么也没有
    将安装驱动后产生的三个文件msbase.jar;mssqlserver.jar;msutil.jar
    放到C:\j2sdk1.4.2_05\jre\lib\ext目录下就可以编程了,不需要另外配置环境变量了!然后试着运行下面的代码!
     import java.sql.*;
     import java.io.*;
     import java.util.*;
     
     /**
     6.    This program tests that the database and the JDBC
     7.    driver are correctly configured.
     */
     class TestDB
     {
        public static void main (String args[])
        {
           try
           {
              runTest();
           }
           catch (SQLException ex)
           {
              while (ex != null)
              {
                 ex.printStackTrace();
                 ex = ex.getNextException();
             }
           }
           catch (IOException ex)
           {
              ex.printStackTrace();
           }
        }    /**
    32.       Runs a test by creating a table, adding a value, showing the table contents, and
    33.       removing the table.
    34.    */
        public static void runTest()
           throws SQLException, IOException
        {
           Connection conn = getConnection();
           try
           {
              Statement stat = conn.createStatement();          ResultSet result = stat.executeQuery("SELECT * FROM Mst_Company");
              while(result.next())
             {
             System.out.println(result.getString(1));
             }
           }
           finally
           {
              conn.close();
           }
        }    /**
           Gets a connection from the properties specified
           in the file database.properties
          @return the database connection
        */
        public static Connection getConnection()
           throws SQLException, IOException
        {
    try
    {
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); 
    }
    catch(Exception e)
    {
    System.out.println(e);
    }       String url ="jdbc:microsoft:sqlserver://192.168.1.24:1433;DatabaseName=marunaka";
           String username = "dbuser";
           String password = "qaz123";       return DriverManager.getConnection(url, username, password);
        }
     }试着修改一下,ip地址,数据库名,用户名,密码,sql语句,你就可以运行,很快就满足你的要求了!