当前位置: 技术问答>java相关
JDBC问题 加分加分
来源: 互联网 发布时间:2015-05-18
本文导语: jdbctest.java ------------------------------------------------- import java.sql.*; import java.util.*; public class jdbctest { public static void main(String[] args) throws SQLException, ClassNotFoundException { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connect...
jdbctest.java
-------------------------------------------------
import java.sql.*;
import java.util.*;
public class jdbctest
{
public static void main(String[] args) throws SQLException, ClassNotFoundException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:test","sa","hcg888");
Statement s = c.createStatement();
ResultSet r = s.executeQuery("SELECT testcol from testtable");
while(r.next())
{
System.out.println(r.getString("testcol"));
}
}
}
-------------------------------------------------
运行完全正常,没有错误!
jdbc.jsp
-------------------------------------------------
-------------------------------------------------
在tomcat中运行显示错误
javax.servlet.ServletException: No suitable driver
经确认,问题出在
Connection c = DriverManager.getConnection("jdbc:odbc:test","sa","hcg888");
这一行
请高手解答,万分感激!
-------------------------------------------------
import java.sql.*;
import java.util.*;
public class jdbctest
{
public static void main(String[] args) throws SQLException, ClassNotFoundException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:test","sa","hcg888");
Statement s = c.createStatement();
ResultSet r = s.executeQuery("SELECT testcol from testtable");
while(r.next())
{
System.out.println(r.getString("testcol"));
}
}
}
-------------------------------------------------
运行完全正常,没有错误!
jdbc.jsp
-------------------------------------------------
-------------------------------------------------
在tomcat中运行显示错误
javax.servlet.ServletException: No suitable driver
经确认,问题出在
Connection c = DriverManager.getConnection("jdbc:odbc:test","sa","hcg888");
这一行
请高手解答,万分感激!
|
给tomcat的jvm加上jdbc driver的classpath.
|
Connection c = DriverManager.getConnection("jdbc:odbc:test","sa","hcg888");这句语法没错啊
你访问的数据库所配置的对应数据源的名字是不是test啊,注意大小写
密码和用户是不是匹配?
再者,是不是访问远程数据库?如果是的话就和网络有关了
你访问的数据库所配置的对应数据源的名字是不是test啊,注意大小写
密码和用户是不是匹配?
再者,是不是访问远程数据库?如果是的话就和网络有关了
|
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection ("jdbc:oracle:thin:@172.18.8.4:1521:ORCL", "sa","hcg888");
conn = DriverManager.getConnection ("jdbc:oracle:thin:@172.18.8.4:1521:ORCL", "sa","hcg888");