4 回答

TA貢獻(xiàn)1111條經(jīng)驗 獲得超0個贊
s是client語言,node是服務(wù)端技術(shù),服務(wù)端技術(shù)才能連接mysql??梢詤⒖?a >nodejs連接mysql

TA貢獻(xiàn)1843條經(jīng)驗 獲得超7個贊
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e) {}
//定義所要用到的三個數(shù)據(jù)庫應(yīng)用對象
Connection con=null; //連接對象
Statement sql=null; //Statement對象(SQL語句)
ResultSet rs=null; //結(jié)果集對象
//進(jìn)行數(shù)據(jù)源的連接
try{
con=DriverManager.getConnection ("jdbc:mysql://localhost/scutcs","","");//連接數(shù)據(jù)庫的url 用戶名和密碼
sql=con.createStatement();
String to="Select * From user1 Where username='"+username+"'";
rs=sql.executeQuery(to); //根據(jù)所定義的Statement執(zhí)行生成相應(yīng)的結(jié)果集并存在RS中
if(rs.next()) //判斷結(jié)果集是否為空,如果不為空則表示有記錄
{
out.print("<script>alert('用戶名 "+xm+"已存在,請另選一個!');history.back();</script>");//如果存在返回注冊頁面
}
else
}
catch (SQLException e)
{ out.print(e);
}
PS.這樣不安全
添加回答
舉報