我用的是sql server2008 跟Eclipse,单独运行都没问题 但是Eclipse java语句就是 连接不到数据库 求帮忙!
Connectioncon;Statementstmt;ResultSetrs;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriv...
Connection con ;
Statement stmt;
ResultSet rs ;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e){System.out.print(e);}
try{ // Establish the connection.
//String connectionUrl = "jdbc:sqlserver://10.0.22.68:1433;databaseName=test";
//String user="sa";
//String password="123456";
con = (Connection) DriverManager.getConnection("jdbc:odbc:test","sa","123456");
//System.out.print(con.toString()+"<br />");
// Create and execute an SQL statement that returns some data.
String SQL = "SELECT * FROM student";
stmt = (Statement) ((java.sql.Connection) con).createStatement();
rs = ((java.sql.Statement) stmt).executeQuery(SQL);
报错:[Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source) 展开
Statement stmt;
ResultSet rs ;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e){System.out.print(e);}
try{ // Establish the connection.
//String connectionUrl = "jdbc:sqlserver://10.0.22.68:1433;databaseName=test";
//String user="sa";
//String password="123456";
con = (Connection) DriverManager.getConnection("jdbc:odbc:test","sa","123456");
//System.out.print(con.toString()+"<br />");
// Create and execute an SQL statement that returns some data.
String SQL = "SELECT * FROM student";
stmt = (Statement) ((java.sql.Connection) con).createStatement();
rs = ((java.sql.Statement) stmt).executeQuery(SQL);
报错:[Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source) 展开
4个回答
展开全部
是不是没有升级?我是用eclipse学J2ME的,安好eclipse后,还要导入eclipse me ,才可以正常使用。希望对你有点启示
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
导入sql server2008的jar文件。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你那个不是纯驱动吧??你是用数据源做的不?是不是数据源的名字错了?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询