📄 conn.java~1~
字号:
package base.db;
import java.sql.*;
public class Conn
{
private static Connection con;
private Statement stmt;
private ResultSet rs;
private static String drivername="com.mysql.jdbc.Driver";
private static final String url="jdbc:mysql://localhost/test?user=root&password=yousufu";
public static synchronized Connection getCon() throws Exception{
try{
Class.forName(drivername);
con=DriverManager.getConnection(url);
return con;
}
catch(SQLException e){
System.err.println(e.getMessage());
throw e;
}
}
public Statement getStmtread() {
try {
con = getCon();
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
return stmt;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
}
/**
*output parameter: Data
*input parameter: SQL select sentence
*modify time: 4/29/2006
*/
public ResultSet getRs(String sql) {
try {
stmt = getStmtread();
rs = stmt.executeQuery(sql);
return rs;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
}
/**
*output parameter: not in order select in str SQL
*modify time: 4/29/2006
*/
public Statement getStmt() {
try {
con = getCon();
stmt = con.createStatement();
return stmt;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
}
/**
*method explain: Close DataBase Connection
*modify time: 4/29/2006
*/
public synchronized void close() {
try {
if (rs != null) {
rs.close();
rs = null;
}
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
try {
if (stmt != null) {
stmt.close();
stmt = null;
}
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
try {
if (con != null) {
con.close();
con = null;
}
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -