/*這是我寫的一個(gè)java類,照著網(wǎng)上敲的代碼,代碼內(nèi)容也理解,用as連接mysql在學(xué)習(xí)當(dāng)中,希望大神指點(diǎn)一下,
感激不盡*/
public?class?renWu?{
????public?static?void?main(String?[]?args){
????????Connection?conn=null;
?????????String?driver?=?"com.mysql.jdbc.Driver";//MySQL?驅(qū)動(dòng)
?????????String?url?=?"jdbc:mysql://localhost:3306/TASK";//MYSQL數(shù)據(jù)庫連接Url
?????????String?user?=?"root";//用戶名
?????????String?password?=?"123456";
????????try?{
????????????Class.forName(driver);
????????????try?{
????????????????conn=?DriverManager.getConnection(url,user,password);
????????????????if?(conn!=null){
????????????????????System.out.println("成功");
????????????????}else?{
????????????????????System.out.println("失敗");
????????????????}
????????????}?catch?(SQLException?e)?{
????????????????e.printStackTrace();
????????????}
????????}?catch?(ClassNotFoundException?e)?{
????????????e.printStackTrace();
????????}
????}
????}
添加回答
舉報(bào)
0/150
提交
取消