加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

com包

发布时间:2020-12-12 15:28:13 所属栏目:MsSql教程 来源:网络整理
导读:package com; import java.sql.*; public class DBConnection { ?Connection con; ?public DBConnection(){ ??String url="jdbc:oracle:thin:@localhost:1521:mis"; ?//?String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=book"; ??Strin

package com;
import java.sql.*;
public class DBConnection {
?Connection con;
?public DBConnection(){
??String url="jdbc:oracle:thin:@localhost:1521:mis";
?//?String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=book";
??String user="scott";
??String password="tiger";
??
??try {
???Class.forName("oracle.jdbc.driver.OracleDriver");
?//??Class.forName("com.mircosoft.jdbc.sqlserver.SQLServerDriver");
??} catch (ClassNotFoundException e) {
???e.printStackTrace();
??}
??try {
???con=DriverManager.getConnection(url,user,password);
??} catch (SQLException e) {
???e.printStackTrace();
??}
?}
?public Connection getConnection(){
??return con;
?}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package com;

import java.util.ArrayList;

import java.sql.*;

import actionform.bookform;

public class bookdao { ? ? ?public ArrayList getSelect(String sql){ ??ArrayList list= new ArrayList(); ??DBConnection db=new DBConnection(); ??Connection con=db.getConnection(); ??try { ???Statement stm= con.createStatement(); ???ResultSet rs=stm.executeQuery(sql); ??? ???while(rs!=null&&rs.next()){ ????bookform b=new bookform(); ????b.setId(rs.getString("id")); ????b.setAuthor(rs.getString("author")); ????b.setTitle(rs.getString("title")); ????b.setPublish(rs.getString("publish")); ????b.setTime(rs.getString("time")); ????b.setPrice(rs.getString("price")); ????list.add(b); ???} ??} catch (SQLException e) { ???e.printStackTrace(); ??} ??return list; ?} ?public int getadd(String sql){ ?? ??DBConnection DB= new DBConnection(); ??Connection con =DB.getConnection(); ???int i=0; ??Statement stm; ??try { ???stm = con.createStatement(); ???i=stm.executeUpdate(sql); ??} catch (SQLException e) { ???e.printStackTrace(); ??} ??return i; ?} } ?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读