java连接sql server数据库的代码如何改成连接mysql_java连接server sql 2000数据库怎么修改成连接mysql数据库?/**/里面的是原来的代码,后来连接是自己添的...

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+"' ";

这句话是什么意思

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值