Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JAVA - > mysql.jdbc
24-03-2011, 04:24 PM,
Post: #1
JAVA - > mysql.jdbc
Code:
import java.sql.*;

   public class Connect
   {
       public static void main (String[] args)
       {
           Connection conn = null;

           try
           {
               Class.forName ("com.mysql.jdbc.Driver").newInstance ();
               conn = DriverManager.getConnection ("jdbc:mysql://127.0.0.1:3306","root","");
               System.out.println ("Database connection established");
           }
           catch (Exception e)
           {
               System.err.println ("Cannot connect to database server");
           }
           finally
           {
               if (conn != null)
               {
                   try
                   {
                       conn.close ();
                       System.out.println ("Database connection terminated");
                   }
                   catch (Exception e) {
                   }
               }
           }
       }
   }

rasa mcm kod atas tu dah betol.. bila kumpil OK..bila execute..
kuar error "Cannot connect to database server". Hurmm.. salah ke string conn tu ?

kod ni dibuat atas
+ xammp
+ dlm plain kod.

kalau buang error code tu..dgn print e terus:
Code:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

driver ke masalah? mcmna mau set manual?
Reply
24-03-2011, 04:31 PM,
Post: #2
RE: JAVA - > mysql.jdbc
conn = DriverManager.getConnection ("jdbc:mysql://127.0.0.1:3306","root","");

cuba padam tu tgk
puas sudah menanam ubi, nenas juga dibeli orang, puas sudah aku berbakti, pengganas juga dipandang orang

Quote:A true warrior need blood on his sword; A true pirate never afraid to sail the red sea.
Reply
24-03-2011, 04:39 PM,
Post: #3
RE: JAVA - > mysql.jdbc
Masokis dah pasang class MySQL untuk JDBC tu? MySQL nye driver takde by default kalau aku tak silap.

  ▲
▲ ▲
Spoiler:

surah Ali Imran Ayat 31

Reply
24-03-2011, 04:41 PM, (This post was last modified: 24-03-2011, 04:41 PM by fatah.)
Post: #4
RE: JAVA - > mysql.jdbc
http://dev.mysql.com/downloads/connector/j/ ???
̿ ̿ ̿̿'̿̿\̵͇̿̿\=(•̪●)=/̵͇̿̿/'̿̿ ̿ ̿ ̿ - انا کڤيتݢولوڠ
http://fatah.afraid.org/
[Image: 763440762.png]
Reply
24-03-2011, 04:42 PM,
Post: #5
RE: JAVA - > mysql.jdbc
http://dev.mysql.com/downloads/connector/j/

  ▲
▲ ▲
Spoiler:

surah Ali Imran Ayat 31

Reply
24-03-2011, 04:46 PM,
Post: #6
RE: JAVA - > mysql.jdbc
(24-03-2011, 04:41 PM)kapitgulung Wrote: http://dev.mysql.com/downloads/connector/j/ ???

(24-03-2011, 04:42 PM)ak47suk1 Wrote: http://dev.mysql.com/downloads/connector/j/

urmm..betol..xde driver.. patutlah..
dah ada download J-driver tu.. tapi mcmna nak pasang ? kat README pun cter ttg lesen je.

maaf, xde / xpernah buat java guna db.. hari ni saje2 belajar.tambah ilmu...
mcma nak load driver ni yep.

kalau guna netbeans, import libary tu kat properties je.. klu guna IDE cam Jcreator?
Reply
24-03-2011, 05:12 PM,
Post: #7
RE: JAVA - > mysql.jdbc
http://www.developer.com/java/data/artic...tarted.htm

Rasa aku boleh follow guide kat atas tu guna IDE apa2 pun. Lama tak guna JAVA. Database pun time aku belajar guna ODBC je.

  ▲
▲ ▲
Spoiler:

surah Ali Imran Ayat 31

Reply
11-04-2011, 10:10 AM,
Post: #8
RE: JAVA - > mysql.jdbc
masokis guna apache tomcat ke?sy pun tak tau sangat tapi kalau nak buat servlet jsp ni besenya bubuh mysql connector tu di dalam WEB-INF => lib
buat folder baru namanya lib dalam WEB-INF dan bubuhla mysql connector disitu.. semoga berjaya GayFace
Reply
18-09-2011, 07:07 PM, (This post was last modified: 18-09-2011, 07:08 PM by fl4m3.)
Post: #9
RE: JAVA - > mysql.jdbc
code btul dah tu,drive mysql-connector xde kot. try add lib tu -WEB-INF/lib
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Soalan Java darknite 10 791 27-11-2013, 01:47 PM
Last Post: darknite
  soalan java. hard3 4 898 10-05-2013, 10:33 PM
Last Post: JejakaPemalu
  [help] inputfile java please click me to know more Timon 0 387 14-04-2013, 10:02 PM
Last Post: Timon
  [problem]with java tcp client and server chat pron3t 1 547 26-02-2013, 01:21 PM
Last Post: muhaznar
  java API Timon 3 814 09-12-2012, 09:58 PM
Last Post: lamki
  java background music library Timon 0 437 09-12-2012, 05:21 PM
Last Post: Timon
  JAVA Layout... mana 1 feveret :P 127001 7 1,662 03-12-2012, 10:32 AM
Last Post: Wushipher
  Java | MS Excell 127001 5 1,031 29-07-2012, 12:41 AM
Last Post: lamki
  Tutorial: Menghubungkan SQLite Dengan Java s3m00t 4 1,272 25-07-2012, 02:40 AM
Last Post: s3m00t
  extract database from mysql crashman_xx 3 872 28-05-2012, 02:14 PM
Last Post: crashman_xx

Forum Jump: