Jump to content
Sign in to follow this  
budak

Java Oh Java

Recommended Posts

akum...kat sini adik nak tanya sikit ler pasal java ni.adik kena buat projek ATM.alahai mesin keluar duit tu. ni lebih kurang assg ler. so kat sini adik bukan nak suruh abang2 suapkan info2 pasal ni.cuma adik nak tau pasal bagaimana nak connect antara java dan mySQL. kalau ada url ker atau apa2 jer ler tunjuk ajar adik alu2kan.dan jugak adik nak tanya ok ker kalau pakai mySQL ni. atau ada alternatif lain? sebab database ini nak simpan nama,password dan lain2 ler.ok tima kasih.

Share this post


Link to post
Share on other sites

kena guna JDBC leh check macam mana nak buat kat mysql.org gi kat tutorial.. and dont forget to download java connecter daripada mysql..

Share this post


Link to post
Share on other sites

rasenya ko nye assg dh anta so aku leh reveal sket camne nk connect ngan mysql. ni antara kodnya mase aku buat assg dulu. enjoy!

* snip *


public void jdbcConnect(String dsn)
{
Connection con;
String url = "jdbc:mysql://localhost:3306/" + dsn;

try
{
Class.forName ("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, "root", "");

DatabaseMetaData dma = con.getMetaData ();

System.out.println("\nConnected to " + dma.getURL());
System.out.println("Driver " + dma.getDriverName());
System.out.println("Version " + dma.getDriverVersion());
System.out.println("");
}
catch (SQLException ex)
{
while (ex != null)
{
System.out.println ("SQLState: " + ex.getSQLState ());
System.out.println ("Message: " + ex.getMessage ());
System.out.println ("Vendor: " + ex.getErrorCode ());
ex = ex.getNextException ();
System.out.println ("");
}
System.out.println("Connection to the database error");
}
catch (java.lang.Exception ex)
{
ex.printStackTrace ();
}
}
[/codebox]

*snip*

tapi ko jgn lupa plak donlod dia nye java connector bak kata DevGuy kite.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...