📄 dbbean.java
字号:
package test;
import java.sql.*;
import java.util.*;
import java.io.*;
import javax.sql.DataSource;
public class DbBean implements Serializable
{
private static Connection con;
public DbBean()
{
}
public static synchronized Connection getCon() throws Exception
{
if (con == null)
{
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url = "jdbc:mysql://localhost/test";
con = DriverManager.getConnection(url, "root", "200405");
return con;
}
catch (Exception e)
{
throw e;
}
}
return con;
}
public ResultSet getRs(String sql) throws Exception
{
try
{
con = getCon();
Statement stmt = con.createStatement();
return stmt.executeQuery(sql);
}
catch (Exception e)
{
throw e;
}
}
public boolean Update(String sql) throws Exception
{
try
{
con = getCon();
Statement stmt = con.createStatement();
if (stmt.executeUpdate(sql) == 1)
return true;
return false;
}
catch (Exception e)
{
throw e;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -