java连接server sql 2000数据库怎么修改成连接mysql数据库?/**/里面的是原来的代码,后来连接是自己添的
publicclassDBOperation{/*privateConnectioncon;publicConnectiongetConnection(){try{Cla...
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+"' ";
这句话是什么意思 展开
{
/*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+"' ";
这句话是什么意思 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询