要用java連接mysql以下列的程式碼:
import java.sql.*;
public class mysql_test {
public static void main(String[] args) {
try{
// load mysql driver
Class.forName("com.mysql.jdbc.Driver");
// connecte
Connection myconn = DriverManager.getConnection(
"jdbc:mysql://localhost/TradeDB", "user", "password");
System.out.println("link success!!!!");
}catch(ClassNotFoundException e){
System.out.println("cann't find");
}catch(SQLException e){
System.out.println("db connect failure");
}
}
}
其中的 user, password改成自己要用的
用eclispe記得要在properties中,將driver.jar引入
1.20.2005
Java - mysql - connetor
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言