如何在tomcat中配置jdbc连接池并在jersey中使用

时间:2016-08-23 06:32:48

标签: java maven tomcat jdbc jersey

您好我正在尝试从连接池获取数据库连接。这是我用来获取连接的代码。我正在使用maven和jersey来创建休​​息服务和tomcat 8。

SetAbsolutePosition()

但我得到了例外

iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imageByte);
float w = image.ScaledWidth;
float h = image.ScaledHeight;
// For the sake of simplicity, I don't crop the image, I just add 20 user units
iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(w + 20, h + 20);
iTextSharp.text.Document document = new iTextSharp.text.Document(page, 10, 10, 10, 10);
PdfWriter writer = PdfWriter.GetInstance(document, outputMemoryStream);
// Please drop the line that prevents closing the output stream!
// Why are so many people making this mistake?
// Who told you you shouldn't close the output stream???
document.Open();
// We add the image to the document, and we let iTextSharp decide where to put it
// As there is just sufficient space to fit the image inside the page, it should fit,
// But be aware of the existence of a leading; that could create side-effects
// such as forwarding the image to the next page because it doesn't fit vertically
document.Add(Image);
document.Close();

用tomcat / conf / server.xml

编写的资源代码
    Context ctx;
    DataSource ds = null;
    try {
        ctx = new InitialContext();
         ds = (DataSource) ctx.lookup("java:/comp/env/jdbc/project");
    } catch (NamingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

tomcat / conf / context.xml中的代码

javax.naming.NameNotFoundException: Name [jdbc/project] is not bound in this Context. Unable to find [jdbc].

如何解决上述问题请帮我解决这个问题

谢谢

1 个答案:

答案 0 :(得分:0)

您是否在web.xml中包含了引用?

<resource-ref>
        <res-ref-name>jdbc/project</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
相关问题