日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

JSP实战型程序连载:通用数据库连接JavaBean

發布時間:2023/12/9 javascript 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JSP实战型程序连载:通用数据库连接JavaBean 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

package online;

?

import java.sql.*;

?

public class DBConn {

? private static String rootpath = "web發布路徑";

? private String sample = "sample";

? private Connection con = null;

? private Statement stmt = null;

? ResultSet rs = null;

? /***************************************************************/

? private static final String DRIVE = "sun.jdbc.odbc.JdbcOdbcDriver";

? //暫時使用jdbc-odbc連接//"com.microsoft.jdbc.sqlserver.SQLServerDriver";

? private static final String USERNAME = "sa";

? private static final String PASSWORD = "123aaa";

? private static final String HOST = "http:127.0.0.1:8080/renshi";

? /*************************************************************/

? //暫時使用jdbc-odbc數據源

? private static final String CONNECTION_STRING = "jdbc:odbc:renshi";

? //"jdbc:microsoft:sqlserver://localhost;1433;";

? public static String getRootPath() {

??? return rootpath;

? }

?

? public DBConn() { //加載驅動

??? try {

????? Class.forName(DRIVE);

??? }

??? catch (ClassNotFoundException e) {

????? System.err.println("DBConn():" + e.toString());

??? }

??? catch (Exception e) {

????? System.err.println("DBConn():" + e.toString());

??? }

? }

?

? public Connection getConnection() { //得到連接

??? try {

????? String strUrl = CONNECTION_STRING;

????? /***********周五晚改動****************************************/

????? //+ "DatebaseName=renshi," + USERNAME +"," + PASSWORD;

????? con = DriverManager.getConnection(strUrl, this.USERNAME, this.PASSWORD);

??? }

??? catch (Exception e) {

????? con = null;

??? }

??? return con;

? }

?

? public void dropConnection() { //關閉連接

??? try {

????? closeStmt();

????? con.close();

??? }

??? catch (Exception ignored) {

??? }

??? finally {

????? con = null;

??? }

? }

?

? public ResultSet executeQuery(String sql) { //執行sql查詢

??? ResultSet rs = null;

??? try {

????? con = getConnection();

????? stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

???????????????????????????????? ResultSet.CONCUR_READ_ONLY);

????? rs = stmt.executeQuery(sql);

??? }

??? catch (SQLException ex) {

????? System.err.println("DBConn.executeQuery():" + ex.getMessage());

??? }

??? return rs;

? }

?

? public int executeUpdate(String sql) { //執行sql更新語句

??? int i=0;

??? stmt = null;

??? rs = null;

??? try {

????? con = getConnection();

????? stmt = con.createStatement();

???? i= stmt.executeUpdate(sql);

????? stmt.close();

????? con.close();

??? }

??? catch (SQLException ex) {

????? System.err.println("DBConn:executeUpdate(0:" + ex.getMessage());

??? }

??? return i;

? }

?

? public void execute(String sql) { //執行sql語句

??? stmt = null;

??? rs = null;

??? try {

????? con = getConnection();

????? stmt = con.createStatement();

????? stmt.execute(sql);

????? stmt.close();

????? con.close();

??? }

??? catch (SQLException ex) {

????? System.err.println("DBConn:excute():" + ex.getMessage());

??? }

? }

?

? public void closeConn() { //關閉sql連接

??? try {

????? stmt.close();

??? }

??? catch (SQLException e) {

????? e.printStackTrace();

??? }

? }

?

? public void closeStmt() { //關閉sql連接

??? try {

????? con.close();

??? }

??? catch (SQLException e) {

????? e.printStackTrace();

??? }

?

? }

?

? /**

?? * main

?? */

? public static void main(String[] args) throws SQLException {

??? DBConn one=new DBConn();

??? ResultSet rs=one.executeQuery("select * from PS_INFO");

??? while(rs.next()){

????? System.out.println(rs.getString(2));

??? }

? }

?

}

?

轉載于:https://www.cnblogs.com/duadu/archive/2006/05/30/6167173.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的JSP实战型程序连载:通用数据库连接JavaBean的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。