publicclassDBOperation{/*privateConnectioncon;publicConnectiongetConnection(){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");con=DriverManager.getConnection("jdbc:odbc...
public class DBOperation
{
/*private Connection con;
public Connection getConnection()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:HR");
}
catch (Exception e)
{
e.printStackTrace();
}
return con;
}*/
static Connection ct = null;
static ResultSet rs = null;
static PreparedStatement ps = null;
private static final String DBDRIVER = "com.mysql.jdbc.Driver";
private static final String DBURL = "jdbc:mysql://localhost:3306/user";
private static final String DBUSER = "root";
private static final String DBPASSWORD = "root";
public static void linkDatabase() throws ClassNotFoundException, SQLException
{
String sql = "select * from user";
Class.forName(DBDRIVER);
ct = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
ps = ct.prepareStatement(sql);
rs = ps.executeQuery();
System.out.println("数据库连接成功");
}
//用户是否存在
public boolean UserExist(String user)
{
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
boolean occupied = true;
String sqlquery ="pro_Search_User_user '"+user+"' ";
try
{
//con = getConnection();
ps = con.prepareStatement(sqlquery);
rs = ps.executeQuery();
if (rs.next() == false )
{
occupied = false;
}
else
{
occupied = true;
}
ps.close();
con.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
return occupied;
}
还有String sqlquery ="pro_Search_User_user '"+user+"' ";
这句话是什么意思
展开