数据库问题????
我写了个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(Database)数据库查看器是一种工具,主要用于查看和分析特定类型的数据库文件,如Paradox和DBF格式。这两种格式在过去的计算机系统和数据库管理中较为常见,尤其在桌面级数据库应用中。
在数据库‘master’中拒绝CREATE DATABASE权限问题的解决方法
### 在数据库‘master’中拒绝CREATE DATABASE权限问题的解决方法#### 背景与问题描述在使用Linq To SQL进行数据库操作时,我们常常需要检查目标数据库是否存在,并在不存在的情况下自动创建它
Oracle 数据库(Database, DB)
数据库基本概念数据库(Database, DB)数据库管理系统(Database Management System, DBMS)数据库管理员( Database Administrator, DBA
idea中database不显示问题的解决
**问题描述**通常,Database面板应该位于IDEA界面的右侧,方便开发者查看和管理数据库连接。
DB文件打开教程
**查看数据库内容**:打开文件后,SQLite Database Browser会显示数据库中的所有表格和字段。用户可以通过点击左侧的表格名称来查看具体的数据内容。


Web 开发
