📄 dbsearch.java
字号:
package com.gzrealmap.oa;
import java.sql.*;
import com.gzrealmap.lib.jdbc.JDBCUtil;
public class dbsearch {
public int row;
public String PK;
public String sql;
public String search;
JDBCUtil logdb;
ResultSet rs;
//*******************************************************************************************
//构造器
public dbsearch() throws Exception
{
logdb = JDBCUtil.getInstance(); //连接数据库
logdb.connect();
logdb.setAutoCommit(false);
}
/**转换成数据库用的编程
* @param String str 设置 str,这个str是我们插进数据库用的东西
* @exception java.lang.SQLException
* @exception NullPointerException throw when parameter n is null
*/
private String toGBK(String str) throws Exception
{
//String temp = new String(str.getBytes("GBK"),"ISO8859_1" );
String temp = str;
return temp;
}
private String toISO(String str) throws Exception
{
String temp = new String(str.getBytes("ISO8859_1"),"GBK" );
return temp;
}
//用于结束并关闭数据库
public void end() throws Exception
{
logdb.commit();
logdb.setAutoCommit(true);
logdb.disconnect();
}
//方法:
//*******************************************************************************************
//没有参数的时候,必须先设置。
public boolean createstatement() throws Exception
{
if(rs!=null)
{
rs.close();
}
//.out.println (sql);
rs = logdb.queryforUpdate(sql);
return true;
}
public boolean createstatement(String sql2) throws Exception
{
setSQL(sql2);
if (this.createstatement())
{
return true;
}
return false;
}
/**
*用于建立sql
*/
public boolean dbsearchstatement(String pkcol, String table, String serachcol, String keyword) throws Exception
{
if (!pkcol.equals("*"))
{ setSerach(pkcol);}
keyword=toISO(keyword);
String sql1= "select "+ pkcol +" from "+table+" Where "+serachcol+" like '%"+ keyword +"%'";
//System.out.println(sql1);
if (createstatement(sql1))
{
return true;
}
return false;
}
public boolean dbsearchstatement(String pkcol, String table, String wherestatic) throws Exception
{
if (!pkcol.equals("*"))
{ setSerach(pkcol);}
String sql1= "select "+ pkcol +" from "+table+" "+wherestatic;
//System.out.println(sql1);
if (createstatement(sql1))
{
return true;
}
return false;
}
public boolean dbsearchstatement( String serachcol, String keyword) throws Exception
{
if (dbsearchstatement("*", " DirectoryFile ", serachcol, keyword) )
{
return true;
}
return false;
}
//*******************************************************************************************
public boolean get() throws Exception
{
if (rs.absolute(row))
{
PK = rs.getString (1);
return true;
}
return false;
}
public boolean get (int row) throws Exception
{
setRow (row);
if (get())
{
return true;
}
return false;
}
public boolean getfileinfo (int row) throws Exception
{
if (rs.absolute(row))
{
PK = rs.getString ("FileID");
return true;
}
return false;
}
//*******************************************************************************************
//下面这一部分是设置属性
public void setSQL (String sql)
{
this.sql = sql;
}
//读第几条
public void setRow (int row)
{
this.row = row;
}
public void setSerach(String search)
{
this.search=search;
}
//*******************************************************************************************
//获取值
public String getPK()
{
return PK;
}
//*******************************************************************************************
//字符转换成int
public int StrTOint(String str)
{
int temp=Integer.valueOf(str).intValue();
return temp;
}
public long StrTOlong(String str)
{
long temp =Integer.valueOf(str).longValue();
return temp;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -