ÓÃjavaÁ¬½ÓMySqlÊý¾Ý¿â
Ò»¸ö¼òµ¥Ê¾Àý--
1£¬×¼±¸£ºMySQLÊý¾Ý¿âÇý¶¯°ü¡¾mysql-connector-java-5.1.10-bin.jar¡¿µ¼Èë
2£¬´´½¨²âÊÔÁ¬½ÓÖ÷³ÌÐò
package mysqlConnection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class JdbcDemo {
public static void main(String[] args) {
try {
//Êý¾Ý¿âÁ¬½ÓMySQL
Connection conn=null;
Statement stmt=null;
//MySQLÇý¶¯Ãû
String className="com.mysql.jdbc.Driver";
//ÒªÁ¬½ÓµÄURL,localhostÊÇÁ¬½Ó±¾µØ£¬Èç¹ûÁ¬½ÓÆäËû»úÆ÷¸ÄΪIPµØÖ·3306ÊÇMysqlĬÈ϶˿ڣ¬testÊÇÄãÒª²Ù×÷µÄÊý¾Ý¿âµÄÃû³Æ£¬Êý¾Ý¿âÒªÓвÅÐÐ
String url="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8";
//mySqlµÄÓû§ÃûÃÜÂëÒª¸ÄΪÄã×Ô¼ºµÄmysqlÊý¾Ý¿âµÄÓû§Ãû¡¢ÃÜÂë
String user="root";
String password="1314520";
//ÏÂÃæÈýÐÐÊǹ̶¨Ð´·¨
Class.forName(className);
conn=DriverManager.getConnection(url, user, password);
stmt=conn.createStatement();
//¿ªÊ¼²åÈë²Ù×÷£¬ut_testÊÇtestÊý¾Ý¿âÖеÄÒ»ÕÅ±í£¬ÓÐname,age,emailÈý¸ö×ֶΣ¬²åÈëµÄÖµÊÇ'ÁõÒü',22,'354559242@qq.com'¡£
String sql="insert into ut_test(name,age,email) values ('ÁõÒü',22,'354559242@qq.com') ";
//Ö´ÐвÙ×÷
stmt.execute(sql);
System.out.println("²åÈë³É¹¦£¡");
} catch(Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Ïà¹ØÎĵµ£º
¡¡finalÀࣺΪ·ÀÖ¹ËûÈË´ÓÄãµÄÀàÉÏÅÉÉúÐÂÀ࣬´ËÀàÊDz»¿ÉÀ©Õ¹µÄ¡£
¡¡¡¡¶¯Ì¬µ÷ÓñȾ²Ì¬µ÷Óû¨·ÑµÄʱ¼äÒª³¤¡£
¡¡¡¡³éÏóÀࣺ¹æ¶¨Ò»¸ö»ò¶à¸ö³éÏó·½·¨µÄÀà±¾Éí±ØÐ붨ÒåΪabstract¡£
¡¡¡¡Àý£º public abstract string getDescripition
¡¡¡¡JavaÖеÄÿһ¸öÀ඼ÊÇ´ÓObjectÀàÀ©Õ¹¶øÀ´µÄ¡£
¡¡¡¡objectÀàÖеÄequalºÍtoString·½·¨¡ ......
Æô¶¯£ºnet start mySql;
½øÈ룺mysql -u root -p/mysql -h localhost -u root -p databaseName;
ÁгöÊý¾Ý¿â£ºshow databases;
Ñ¡ÔñÊý¾Ý¿â£ºuse databaseName;
Áгö±í¸ñ£ºshow tables£»
ÏÔʾ±í¸ñÁеÄÊôÐÔ£ºshow columns from tableName£»
½¨Á¢Êý¾Ý¿â£ºsource fileNa ......
Õ⼸ÌìËù×÷µÄ¹¤×÷Éæ¼°µ½Êý¾Ý¿âÐÐתÁеÄÎÊÌâ
¼Ç¼һϳöÏֵĴíÎó£¬ÒÔÃâÒÔºóÔÙ·¸
¾ÙÍøÉÏ×îͨË×µÄÀý×Ó°É
Name Subject Result
ÕÅÈý ÓïÎÄ 80
ÕÅÈý Êýѧ 90
ÕÅÈý ÎïÀí &n ......
ËùÒÔ³ýÁ˸øÕË»§È¨ÏÞÒÔÍâ »¹ÓÐÐÞ¸Ä /etc/mysql/my.cnf
ÕÒµ½ bind-address = 127.0.0.1 ÐÞ¸ÄΪ bind-address = 0.0.0.0
ÖØÆômysql : sudo /etc/init.d/mysql restart
·ñÔò»á±¨ ERROR 2003 (HY000): Can't connect to MySQL server on 'x.x.x.x' (111)
ºÃ°É ÎÒÊÇmysql²ËÄñ ÒÔÇ°¶¼ÊÇ×ßlocalhostµÄ
......