WebLogic The JSP Connection database

Source: Internet
Author: User
Tags domain server

First, the introduction of JSP development, the general need for front-end development tools and background services. WebLogic is a large system that integrates tools and services. It is important to take into consideration that the BEA company's WebLogic minimum requirements to configure memory 512M, even if the server parameter file optimization, still can not solve the problem.

Second, install the configuration WebLogic

Windows installation nothing to say.
After installation, WebLogic automatically built three servers (workshop,integration,portal), users can choose, not happy can also create their own, the content of the creation of "WebLogic Domain configuration Method" A article has been very detailed. The simple approach is to choose from the template selection, where the tool->weblogic the basic WebLogic workshop domain template of the Server-> Configuration Wizard.

Third, create a new application, add a Web project,

Domain server created well, select File-> new-> application, select service, select Application, complete creation. Add a Web project to the application you are building.


Four, Web application

Add a database Web application. In the Web project, add the JSP file and Java Class. This example uses index.jsp,error.jsp, clsdb.java,db.properties four files.

The directory structure is as follows:

Application name \web project name \web-inf\ ...
Application name \web project name \index.jsp
Application name \web project name \error.jsp
Application name \web project name \db.properties
Application name \web project name \javacls\clsdb.java

index.jsp Start page, data browsing
--------------------------------------------------

<body>
<%
Javacls.clsdb db=new Javacls.clsdb ();
Boolean I;
I=db.openconnection ();
if (i=true)
{
Java.sql.ResultSet rs=db.exequery ("Select D from Test");
Rs.next ();
while (!rs.isafterlast ())
{
Out.println (Rs.getobject (1));
Rs.next ();
}
}

%>
</body>

Error.jsp Error Display page
--------------------------------------------------

<p>
An error occurred
<br>
Error Description:
<%=exception.tostring ()%>
<br>
Error Reason:
<%=exception.getmessage ()%>
</p>

Clsdb.java database operation class, very typical database application method
--------------------------------------------------

Package JavaBean;

public class Clsdb
{
Java.sql.Connection Cn=null;
Java.sql.Statement Sqlstm=null;
Java.sql.ResultSet Rs=null;

Public Clsdb ()
{}

Open a database connection
public boolean openconnection ()
{

Read settings
Java.util.Properties prop=new java.util.Properties ();
Try
{
Java.io.InputStream In=this.getclass (). getResourceAsStream (".. /db.properties ");
Prop.load (in);
if (in!=null) in.close ();
}
catch (Java.io.IOException e)
{
System.out.println ("[opencn] config file open error!") ");
return false;
}

String Jdbc=prop.getproperty ("Drivers");
String url=prop.getproperty ("url");
String user=prop.getproperty ("user");
String password=prop.getproperty ("password");

Load JDBC
Try
{
Class.forName (JDBC);
}
catch (Java.lang.ClassNotFoundException e)
{
System.out.println ("[OPENCN] load JDBC driver error!") ");
return false;
}
Open a database connection
Try
{
This.cn=java.sql.drivermanager.getconnection (Url,user,password);
}
catch (Exception e)
{
E.printstacktrace ();
return false;
}
return true;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.