| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 615 人关注过本帖
标题:看一下呀!JSP问题之最!!
只看楼主 加入收藏
sropcom
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2005-11-28
收藏
 问题点数:0 回复次数:2 
看一下呀!JSP问题之最!!
package database;

import java.sql.*;

import java.util.*;
import sun.io.*;

public class OPDB{

//DBConnectionMannager connMgr;
Connection conn =null;

Statement sqlStatement =null;

ResultSet results =null;

ResultSet retemp =null;

ResultSetMetaData resultsMeta =null;

boolean status;

String sql;

int columns;

long rowcount =0;

//连接数据库

public void connection(){

try{
/*DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

this.conn =DriverManager.getConnection ("jdbc:oracle:thin:@10.10.10.220:1521:market","sz_hk", "sz_hk");
*/
//connMgr = DBConnectionMannager.getInstance();
//conn =connMgr.getConnection("sz_hk");
this.status =true;

}catch(Exception e)

{

this.status =false;

}

}

//连接数据库

public void connection(String con,String username,String password){

try{
con="jdbc:odbc:zhong";

DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());

this.conn =DriverManager.getConnection (con,"sa","342323");

this.status =true;

}catch(SQLException e)

{

this.status =false;

}

}


// 返回连接

public Connection getConn(){

/* try{
DBConnectionMannager connMgr;
connMgr = DBConnectionMannager.getInstance();
Connection conn =connMgr.getConnection("sz_hk");
if(conn !=null)
this.status =true;

else
this.status =false;
}catch(Exception e){
System.out.println( e.toString());
}*/
return this.conn ;

}


// 关闭对数据库的连接等。

public void Close(){

try{

if(this.conn !=null)

this.conn.close();

if(this.sqlStatement !=null)

this.sqlStatement.close();

if(this.results !=null)

this.results.close();

//this.connMgr.release();
this.status =true;


}catch(SQLException e){

this.status =false;

}

}

//从数据库中选择数据

public synchronized ResultSet select(Connection c,String sql){

int index =0;

//Assign passed arguments

this.conn =c;

this.sql =sql;

try{

//Create Statement Object and Execute SQL

sqlStatement =this.conn.createStatement();

retemp =sqlStatement.executeQuery(this.sql);

this.rowcount =0;

//Get the column count for the result set

this.rowcount =0;

while(this.retemp.next())

this.rowcount++;

if(retemp!=null)

retemp.close();

results =sqlStatement.executeQuery(this.sql);

resultsMeta =results.getMetaData();

this.columns =resultsMeta.getColumnCount();

this.status =true;

return results;

}catch(SQLException e){

this.status =false;

return null;

}

}

//返回结果集的列数目

public int getColumns(){

return this.columns;

}

//返回结果集的行数目

public long getRowcount(){

return this.rowcount;

}

// 修改数据库中的记录。

public void update(Connection c,String sql){

try{

Statement sqlStatement =c.createStatement();

sqlStatement.executeUpdate(sql);

status =true;

}catch(SQLException e){

//set status to flase

status =false;

}

}

//向数据库中插入记录。

public synchronized void insert(Connection c,String sql){

try{

Statement sqlStatement =c.createStatement();

sqlStatement.executeUpdate(sql);

//set status variable to true

this.status =true;

}catch(SQLException e){

//set status variable to true

this.status =false;

}

}

// 删除记录 。

public synchronized void delete(Connection c,String sql){

try{

sqlStatement =this.conn.createStatement();

sqlStatement.executeUpdate(sql);

status =true;

}catch(SQLException e){

//set status to flase

status =false;

}

}

//删除所有记录。

public void deleteAll(String table){

String sql ="delete from "+table;

try{

sqlStatement =this.conn.createStatement();

sqlStatement.executeUpdate(sql);

status =true;

}catch(SQLException e){

status =false;

}

}

//返回对数据库的操作是否成功

public boolean getSuccess(){

return this.status;

}

//转换为中文字符

public String GBK(String action){

try{

byte[] b =action.getBytes("GB2312");

String convert =new String(b,"8859_1");

return convert;

}catch(Exception e){

}

return null;

}
public static String AsciiToChineseString(String s)
{
char[] orig =s.toCharArray();

byte[] dest =new byte[orig.length];

for(int i=0;i<orig.length;i++)

dest[i] =(byte)(orig[i]&0xFF);

try{
ByteToCharConverter toChar =ByteToCharConverter.getConverter("gb2312");
return new String(toChar.convertAll(dest));

}catch(Exception e){}

return s;
}
public String replace(String con ,String tag,String rep){
int j=0;
int i=0;
int k=0;
String RETU="";
String temp =con;
int tagc =tag.length();
while(i<con.length()){
if(con.substring(i).startsWith(tag)){
temp =con.substring(j,i)+rep;
RETU+= temp;
i+=tagc;
j=i;
}
else{
i+=1;
}

}
RETU +=con.substring(j);
return RETU;
}

}

搜索更多相关主题的帖子: JSP 
2005-12-01 16:45
疯子java
Rank: 4
等 级:贵宾
威 望:13
帖 子:328
专家分:0
注 册:2004-9-19
收藏
得分:0 
问题是什么呀

疯言疯语 疯部可及 ---世界法第1章第1节第1条规定 此人由于说话太过于疯!!!其余人等切不可与其交谈! 此人由于说话太过于疯!!!此人的话100%的不能相信
2005-12-01 20:58
sropcom
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2005-11-28
收藏
得分:0 

不能调用那里面的方法呀
比如UPDATE、INSERT、SELECT、DELETE

2005-12-02 13:59
快速回复:看一下呀!JSP问题之最!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020021 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved