📄 dbconnbean.java
字号:
// FrontEnd Plus for JAD
// DeCompiled : DbConnBean.class
package conndb;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.sql.*;
public class DbConnBean
{
private static Connection conn;
private Statement stmt;
private ResultSet rs;
public DbConnBean()
{
}
public void init(Connection conn)
{
try
{
stmt = conn.createStatement();
}
catch(Exception e)
{
System.out.println((new StringBuilder("init:")).append(e.getMessage()).toString());
}
}
public void close()
{
try
{
if(rs != null)
rs.close();
}
catch(Exception e)
{
System.out.println((new StringBuilder("rs.close():")).append(e.getMessage()).toString());
}
try
{
if(stmt != null)
stmt.close();
}
catch(Exception e)
{
System.out.println((new StringBuilder("stmt.close():")).append(e.getMessage()).toString());
}
try
{
if(conn != null)
conn.close();
}
catch(Exception e)
{
System.out.println((new StringBuilder("conn.close():")).append(e.getMessage()).toString());
}
}
public int select(String sql)
{
int k = -10;
init(getConn());
try
{
k = 0;
rs = stmt.executeQuery(sql);
if(rs.next())
k++;
}
catch(Exception e)
{
k = -1;
System.out.println((new StringBuilder("select():")).append(e.getMessage()).toString());
close();
}
close();
return k;
}
public int update(String sql)
{
int k = -10;
init(getConn());
try
{
k = 0;
k = stmt.executeUpdate(sql);
}
catch(Exception e)
{
k = -1;
System.out.println((new StringBuilder("update():")).append(e.getMessage()).toString());
}
close();
return k;
}
public static synchronized Connection getConn()
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String URL="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=booklib";
conn = DriverManager.getConnection(URL, "sa", "sa");
System.out.println("连接建立!");
}
catch(Exception e)
{
System.out.print(e);
}
return conn;
}
public String chStr(String str) throws UnsupportedEncodingException
{
String temp2;
byte temp[] = str.getBytes("ISO8859-1");
temp2 = new String(temp);
return temp2;
}
public ResultSet query(String sql)
{
try
{
rs = stmt.executeQuery(sql);
}
catch(Exception e)
{
e.getMessage();
}
return rs;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -