import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class sqlserver2000 {
Connection dbConn;
String dbUrl = "jdbc:sqlserver://localhost:1433; DatabaseName=test11";
String dbUser = "sa";
String dbPwd = "52111";
String err = "";
private static sqlserver2000 instance;
public sqlserver2000() {
// TODO Auto-generated constructor stub
}
public static sqlserver2000 getInstance()
{
if(instance==null)
{
instance = new sqlserver2000
();
}
return instance;
}
// 连接数据库,返回一个 Connection类型对象
public Connection getConn() {
try {
Class.forName
("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
dbConn = DriverManager.getConnection(dbUrl,dbUser,dbPwd);
} catch (Exception ex) {
dbConn = null;
err = ex.toString();
System.out.println(err);
}
return dbConn;
}
// 获得错误信息
public String getErr() {
return err;
}
//增加记录
public static void addData()
{
Connection dbcon = sqlserver2000.getInstance().getConn();
try {
Statement dbstate = dbcon.createStatement();
String sql = "insert into test.dbo.student (uid,pwd) values ('1452','858')";
dbstate.execute(sql);
dbstate.close();
dbcon.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
出现了Exception in thread "main" java.lang.NoSuchMethodError: main的问题,为什么呢??