📄 mysql basedb.java
字号:
package com.acg.bean.DB;
import java.sql.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class baseDB{
private String userName="root";
private String password="sa";
private Connection connection;
private Connection connT;
private Statement statement;
private ResultSet result;
private String sqlQuery;
private boolean connAvailable;
private boolean resultAvailable;
public void setUserName(String username)
{
this.userName=username;
}
public String getUserName()
{
return this.userName;
}
public void setPassword(String password)
{
this.password=password;
}
public String getPassword()
{
return this.password;
}
public void setSqlQuery(String sqlQuery)
{
this.sqlQuery=sqlQuery;
}
public Connection getConnection()
{
return this.connection;
}
public Connection getAPIConnection()
{
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
//conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/newdatabase?user=sa&password=sa");
this.connT = DriverManager.getConnection("jdbc:mysql://localhost:3306/database?user="+this.userName+"&password="+this.password);
}
catch(Exception e)
{
e.printStackTrace();
}
return connT;
}
public void setConnection(Connection connection)
{
this.connection=connection;
}
public Statement getStatement()
{
setConnection(getAPIConnection());
try
{
this.statement=this.connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
}
catch(Exception e)
{
e.printStackTrace();
}
return this.statement;
}
public ResultSet getResult()
{
getStatement();
try
{
this.result=this.statement.executeQuery(this.sqlQuery);
}
catch(Exception e)
{
e.printStackTrace();
}
return this.result;
}
public void close()
{
try
{
this.result.close();
this.statement.close();
this.connection.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public boolean isConnectionAvailable()
{
try
{
this.connAvailable=!connection.isClosed();
}
catch(Exception e)
{
e.printStackTrace();
}
return this.connAvailable;
}
public boolean isResultSetAvailable()
{
try
{
this.resultAvailable=!this.result.wasNull();
}
catch(Exception e)
{
e.printStackTrace();
}
return this.resultAvailable;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -