2013-07-20 29 views
0

我已經創造了mysql.Now數據庫試圖連接數據庫與程序的連接,但我cant.This是如何建立與數據庫

Class.forName("com.mysql.jdbc.driver"); 
con=DriverManager.getConnection("jdbc:mysql://localhost/hr","abilash","abilash"); 
System.out.println("connected"); 
java.sql.Statement stmt = con.createStatement(); 
System.out.println("Connected Successfully"); 
stmt.executeUpdate("insert into emp (Name) values('"+fnamet.getText()+"') "); 
JOptionPane.showMessageDialog(null,"Item Successfully Added", 
"Confirmation",JOptionPane.INFORMATION_MESSAGE); 

我使用Eclipse和我的我的代碼部分已經加入mysql-connector-java.zip(5.1.25)。我不知道什麼真正的問題是????請幫

+0

你做了什麼錯誤? –

+0

沒有這樣的錯誤。只是它的執行catch塊 –

+0

是的。沒有任何錯誤。 –

回答

4

你錯過的getConnection()

更改端口號

con=DriverManager.getConnection("jdbc:mysql://localhost/hr","abilash","abilash"); 

con=DriverManager.getConnection("jdbc:mysql://localhost:3306/hr","abilash","abilash"); 
+0

Ahha,剛剛記得使用這個端口一次,當我用'mysql' :-) +1這個。 –

相關問題