※ 引述《kaets (哇哈哈)》之銘言:
: 我已經安裝好MYSQL
: 我下載了這個JDBC的DRIVER: mysql-connector-java-3.0.17-ga.zip
: 接下來要怎麼安裝它才能夠跟MYSQL做連接?
: 我的作業系統是WINDOWS
: 請大大指導一下或者給一下教學網站
: 謝謝^^
JDBC Introduction:
http://java.sun.com/docs/books/tutorial/jdbc/overview/index.html
JDBC Basics:
http://java.sun.com/docs/books/tutorial/jdbc/basics/index.html
以下是我去年寫的小範例
這是用Microsoft Access
如果要改成MySQL,可能要改一下DriverManager那一行參數
import java.io.*;
import java.sql.*;
import java.util.*;
public class Main
{
public static void main( String[] args ) throws SQLException
{
Connection conn = null;
Statement stmt = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(
"jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb);" +
"DBQ=C:\\Documents and Settings\\!H45\\桌面\\db1.mdb" );
stmt = conn.createStatement();
String SQL = "insert into data" + " " +
"values ('必勝客','3939889')" + " ";
stmt.executeUpdate(SQL);
conn.close();
System.out.println("Successful");
}
catch(Exception e){e.printStackTrace();}
}
}
Note that JDBC 4.0 had changed something:
http://java.sun.com/javase/6/jcp/beta/apidiffs/index-diffs.html
也許沒能幫上忙...待其他板友補強了...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.205.85