Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
dbconn.java
Package: JSP02.rar [view]
Upload User: top0756
Upload Date: 2022-08-11
Package Size: 6501k
Code Size: 4k
Category:
Jsp/Servlet
Development Platform:
VBScript
- package proj112;
- import java.io.*;
- //import javax.servlet.http.*;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class dbconn {
- //建立一个联接机
- String url="jdbc:odbc:dsn112"; //建立一个Odbc源
- Connection con=null; //Connection对象
- ResultSet rs=null; //建立一个记录集
- PreparedStatement prepstmt = null;
- String userName = "sa";
- String password = "";
- public dbconn(){
- try{
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //用classforname方法加载驱动程序类
- }catch(java.lang.ClassNotFoundException e){ //当没有发现这个加载这个类的时候抛出的异常
- System.err.println(e); //执行系统的错误打印
- }
- }
- public ResultSet executeQuery(String sql){ //可以执行添加删等操作
- try{
- con=DriverManager.getConnection(url,userName,password);
- Statement stmt = con.createStatement(
- ResultSet.TYPE_SCROLL_SENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- rs=stmt.executeQuery(sql);
- }catch(SQLException er){
- System.err.println(er.getMessage());
- }
- return rs;
- }
- public int executeUpdate(String sql){ //数据库的更新操作
- int result=0;
- try{
- con=DriverManager.getConnection(url,userName,password);
- Statement stmt=con.createStatement();
- result=stmt.executeUpdate(sql);
- }catch(SQLException ex){
- System.err.println(ex.getMessage());
- }
- return result;
- }
- public void close(){
- try{
- if(con!=null)
- con.close();
- }catch(Exception e){
- System.out.print(e);
- }try{
- if(rs!=null)
- rs.close();
- }catch(Exception e){
- System.out.println(e);
- }
- }
- public PreparedStatement preparedstatements(String sql) {
- try{
- con=DriverManager.getConnection(url,userName,password);
- prepstmt = con.prepareStatement(sql);
- //PreparedStatement prepstmt = null;
- }catch(SQLException ex){
- System.err.println(ex.getMessage());
- }
- return prepstmt;
- }
- /* public static void main(String[] args) {
- try {
- ConnDB db = new ConnDB();
- //db.executeQuery("select * from student_info";
- ResultSet rs = db.executeQuery("select * from student_info");
- while(rs.next()) {
- System.out.println(rs.getShort(1));
- System.out.println(rs.getString(2));
- }
- //System.out.println("连接数据库成功!");
- }catch(Exception e) {
- e.printStackTrace();
- }
- }*/
- }