Connecting to a database using JavaBean

Source: Internet
Author: User
Tags final getmessage odbc stmt

This is written about JSP call JavaBean Implementation database connection and operation!

First of all, JavaBean's original program.

——————————————————————

Package mywebconn;
Import java.sql.*;
public class Jdbcrs {
//
Static final String sdbdriver= "Sun.jdbc.odbc.JdbcOdbcDriver";
Static final String sconnstr= "Jdbc:odbc:driver={microsoft Access Driver (*.mdb)};D Bq=d:/myweb01/webmodule1/test.mdb" ;
Connection Conn=null;
ResultSet Rs=null;
Public Jdbcrs () {
try {
Class.forName (Sdbdriver);
}
catch (Java.lang.ClassNotFoundException e) {
System.err.println (E.getmessage ());
}
}
The public
Public ResultSet executequery (String sql) {
Rs=null;
try {
Conn=drivermanager.getconnection (SCONNSTR);
Statement stmt=conn.createstatement ();
Rs=stmt.executequery (SQL);
}
catch (SQLException ex) {
System.err.println ("Aq.executequery" +ex.getmessage ());
}
Return RS;
}
public void executeupdate (String sql) {
try {
conn = Drivermanager.getconnection (SCONNSTR);
Statement stmt = Conn.createstatement ();
Stmt.executeupdate (SQL);
Conn.close ();
}
catch (SQLException ex) {
System.err.println ("Aq.executeupdate" +ex.getmessage ());
}
}
public void Close () {
try {
if (!conn.isclosed ()) {
Conn.close ();
}
catch (SQLException ex) {
System.err.println ("Conn.close" +ex.getmessage ());
}
}
}

——————————————————————

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.