ºìÁªLinuxÃÅ»§
Linux°ïÖú

dz̸ÈçºÎÓ¦ÓÃJDBCÁ¬½ÓÊý¾Ý¿âMy SQL

·¢²¼Ê±¼ä:2006-09-23 00:03:22À´Ô´:ºìÁª×÷Õß:fengmayi1
¡¡¡¡×î½üÔÚѧϰÊý¾Ý¿â¿ª·¢µÄһЩʵÀý£¬ÕâÀïdz̸һÏÂÓÃJDBCÁ¬½ÓÊý¾Ý¿âMySQL£¨µ±È»Ò²¿ÉÒÔÁ¬½ÓSQL Sever»òOracleÁË£¬Ö»ÊÇÎÒ¸üϲ»¶¿ªÔ´Èí¼þ£¬Í¬Ê±Ò²¸ü¼òµ¥£©¡£

¡¡¡¡Ê×ÏÈÕýÈ·°²×°ºÃMySQL£¬½¨Á¢ºÃÊý¾Ý¿âstudentinfo

[code]mysql>create database studentinfo;[/code]

¡¡¡¡È»ºó±àдjava´úÂ룬ConnectToMySQL.java

[code]import java.sql.*;
public class ConnectToMySQL {
public static Connection getConnection() throws SQLException ,
java.lang.ClassNotFoundException{
String url = "jdbc:mysql://localhost:3306/studentinfo";
Class.forName("com.mysql.jdbc.Driver");
String userName = "root";
String password = "";
Connection con = DriverManager.getConnection(url,userName,password);
return con;
}
public static void main(String[] args) {
try{
Connection con = getConnection();
Statement sql = con.createStatement();
sql.execute("drop table if exists student");
sql.execute("create table student(id int not null auto_increment,name varchar(20) not
null default 'name',math int not null default 60,primary key(id));");
sql.execute("insert student values(1,'AAA','99')");
sql.execute("insert student values(2,'BBB','77')");
sql.execute("insert student values(3,'CCC','65')");
String query = "select * from student";
ResultSet result = sql.executeQuery(query);
System.out.println("Student±íÊý¾ÝÈçÏ£º");
System.out.println("---------------------------------");
System.out.println("ѧºÅ"+" "+"ÐÕÃû"+" "+"Êýѧ³É¼¨");
System.out.println("---------------------------------");
int number;
String name;
String math;
while(result.next()){
number = result.getInt("id");
name = result.getString("name");
math = result.getString("math");
System.out.println(number + " " + name + " " + math);
}
sql.close();
con.close();

}catch(java.lang.ClassNotFoundException e){
System.err.println("ClassNotFoundException:" + e.getMessage());
}catch(SQLException ex){
System.err.println("SQLException:" + ex.getMessage());
}
}
}[/code]

¡¡¡¡ÇáËɸ㶨£¬Ò»ÏÂΪÊä³ö½á¹û£º

[align=center][/align]

¡¡¡¡Òª×¢ÒâµÄÊÇʹÓÃMySQLÊý¾Ý¿â£¬ÐèÒªÓõ½¶ÔÓ¦µÄJDBCÇý¶¯³ÌÐòmysql-connector-java-5.0.3£¬¿ÉÒÔµ½zySQLµÄ¹Ù·½ÍøÕ¾ÉÏÏÂÔØ(http://www.mysql.org)
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 91 ÌõÆÀÂÛ

  1. 71.70.225.* ÓÚ 2007-07-19 03:00:10·¢±í:

    adult hot comic http://adultcomics17jul.tripod.com/adult_hot_comic.html adult hot comic adult hot comic
    adult book cam comic guest inurl web http://adultcomics17jul.tripod.com/adult_book_cam_comic_guest_inurl_web.html adult book cam comic guest inurl web adult book cam comic guest inurl web
    adult comic evil http://adultcomics17jul.tripod.com/adult_comic_evil.html adult comic evil adult comic evil
    adult comics free http://adultcomics17jul.tripod.com/adult_comics_free.html adult comics free adult comics free
    d adult comics http://adultcomics17jul.tripod.com/d_adult_comics.html d adult comics d adult comics

  2. 85.85.101.* ÓÚ 2007-07-17 16:27:32·¢±í:

    http://efac683e322b8caf81693a0ba180b442-t.xkktxb.org efac683e322b8caf81693a0ba180b442 http://efac683e322b8caf81693a0ba180b442-b1.xkktxb.org efac683e322b8caf81693a0ba180b442 http://efac683e322b8caf81693a0ba180b442-b3.xkktxb.org 8d1f2bfe3cbc5359328d95464cab8b7c