数据库问题????
我写了个bulletins.properties文件
内容为:
db_driver=oracle.jdbc.driver.OracleDriver
db_url=jdbc:oracle:thin:@192.168.0.11:1521:orcl1
db_user=test
db_password=test
在java文件中,我通过下面方式调用
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
public class bulletinshttp extends HttpServlet
{
private static Properties http_props = new Properties();
private static String db_Driver;
private static String db_Url;
private static String db_User;
private static String db_Password;
Connection connect;
public void init(ServletConfig configuration)
throws ServletException
{
super.init(configuration);
try
{
// FileInputStream infile = new FileInputStream("/bulletins/bulletins.properties");
InputStream infile = this.getClass().getResourceAsStream("/bulletins.properties");
http_props.load(infile);
db_Driver = http_props.getProperty("db_driver");
db_Url = http_props.getProperty("db_url");
db_User = http_props.getProperty("db_user");
db_Password = http_props.getProperty("db_password");
infile.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
doPost(req, resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
PrintWriter outhtml;
String driver = db_Driver;
String url = db_Url;
String user = db_User;
String password = db_Password;
String urlextrapath;
resp.setContentType("text/html");
outhtml = resp.getWriter();
/*
outhtml.println ("driver = "+driver);
outhtml.println ("url = "+url);
outhtml.println ("user = "+user);
outhtml.println ("password = "+password);
*/
try
{
Class.forName(driver);
connect = DriverManager.getConnection("url", "user", "password");
urlextrapath = req.getPathInfo();
bulletins bltn = new bulletins();
bltn.connect = connect;
Enumeration enum = req.getParameterNames();
…………………………………………………………………………
…………
}
catch(ClassNotFoundException e)
{
outhtml.println ("Cannot load driver:"+ e.getMessage ());
}
catch(SQLException e)
{
outhtml.println ("SQLException: "+e.getMessage ());
}
finally
{
try
{
if(connect!=null)
connect.close ();
}
catch(SQLException ignored)
{}
}
}
}
另外,在tomcat的common/lib里面已经加了class12.jar及class12.zip
可是最后测试时:却捕捉到下面的错误(在html页面上)
SQLException: No suitable driver
请高手指点,如何调试??
万分感谢:)
内容为:
db_driver=oracle.jdbc.driver.OracleDriver
db_url=jdbc:oracle:thin:@192.168.0.11:1521:orcl1
db_user=test
db_password=test
在java文件中,我通过下面方式调用
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
public class bulletinshttp extends HttpServlet
{
private static Properties http_props = new Properties();
private static String db_Driver;
private static String db_Url;
private static String db_User;
private static String db_Password;
Connection connect;
public void init(ServletConfig configuration)
throws ServletException
{
super.init(configuration);
try
{
// FileInputStream infile = new FileInputStream("/bulletins/bulletins.properties");
InputStream infile = this.getClass().getResourceAsStream("/bulletins.properties");
http_props.load(infile);
db_Driver = http_props.getProperty("db_driver");
db_Url = http_props.getProperty("db_url");
db_User = http_props.getProperty("db_user");
db_Password = http_props.getProperty("db_password");
infile.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
doPost(req, resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
PrintWriter outhtml;
String driver = db_Driver;
String url = db_Url;
String user = db_User;
String password = db_Password;
String urlextrapath;
resp.setContentType("text/html");
outhtml = resp.getWriter();
/*
outhtml.println ("driver = "+driver);
outhtml.println ("url = "+url);
outhtml.println ("user = "+user);
outhtml.println ("password = "+password);
*/
try
{
Class.forName(driver);
connect = DriverManager.getConnection("url", "user", "password");
urlextrapath = req.getPathInfo();
bulletins bltn = new bulletins();
bltn.connect = connect;
Enumeration enum = req.getParameterNames();
…………………………………………………………………………
…………
}
catch(ClassNotFoundException e)
{
outhtml.println ("Cannot load driver:"+ e.getMessage ());
}
catch(SQLException e)
{
outhtml.println ("SQLException: "+e.getMessage ());
}
finally
{
try
{
if(connect!=null)
connect.close ();
}
catch(SQLException ignored)
{}
}
}
}
另外,在tomcat的common/lib里面已经加了class12.jar及class12.zip
可是最后测试时:却捕捉到下面的错误(在html页面上)
SQLException: No suitable driver
请高手指点,如何调试??
万分感谢:)
...全文
相关推荐
DB(数据库查看器)
DB数据库查看器 可查询paradox及dbf数据库文件内容。
在数据库‘master’中拒绝CREATE DATABASE权限问题的解决方法
今天使用Linq To SQL,要求判断数据库是否存在,不存在是自动创建数据库。
Oracle 数据库(Database, DB)
数据库基本概念 数据库(Database, DB) 数据库管理系统(Database Management System, DBMS) 数据库管理员( Database Administrator, DBA) 数据库系统( Database System, DBS ) 关系型数据库 E-R 模型(Entry-Relation)
idea中database不显示问题的解决
主要介绍了idea中database不显示问题的解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
DB文件打开教程
db格式的文件识别与查看。包含文件识别工具winhex的下载地址和数据查看工具sqlitebrowser_200_b1_win的下载地址。


Web 开发
