一个连接数据库出错的问题...
一个连接数据库出错的问题...
编辑时出现如下错误:
Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
程序如下:
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
public class testsql {
public testsql() {
try{
String ODBCName = "java:comp/env/jdbc/sqlserver";
Context ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(ODBCName);
Connection con = ds.getConnection();
Statement sqlStmt = con.createStatement();
}catch (Exception e)
{
System.out.println("" + e.getMessage());
}
}
public static void main(String[] args) {
testsql testsql1 = new testsql();
}
}