jdbc连接mysql数据库
先下载一个mysql的驱动器:(我下的是mysql-connector-java-3.1.11-bin.jar)
将它放到java\lib目录下
在环境变量的CLASSPATH里添加该类(%JAV_HOMG%\lib\mysql-connector-java-3.1.11-bin.jar)
出测试该段代码即可:
import java.net.URL;
import java.sql.*;
public class sqlTest {
public static void main(String[] args) {
try{
String Driver="org.gjt.mm.mysql.Driver";
String URL="jdbc:mysql://localhost:3306/jietest";
String user="root";
String password="2008051082";
Connection con=null;
Statement sm=null;
ResultSet rs=null;
Class.forName(Driver);
con=DriverManager.getConnection(URL,user,password);
String sql="insert into info values('yating','2008052231','13632355056','3','3','2','3');";
sm=con.createStatement();
sm.execute(sql);
String sql2="select * from info";
rs=sm.executeQuery(sql2);
while(rs.next()) {
System.out.println(rs.getString("name")+" "+
rs.getString("id"));
}
System.out.println("Create successfully!");
sm.close();
con.close();
}catch(SQLException ex) {
System.out.println("\n***SQLException caught ***\n");
while(ex!=null) {
System.out.println("SQLState:"+ex.getSQLState());
System.out.println("Message:"+ex.getMessage());
System.out.println("Vendor:"+ex.getErrorCode());
ex=ex.getNextException();
System.out.println("");
}
}catch(java.lang.Exception ex) {
ex.printStackTrace();
}
}
}
相关文档:
MySQL EVENT
来源:http://samyu.blog.51cto.com/344284/146011
event_scheduler:
The MySQL event scheduler is a thread that runs in the background looking for events to execute. It spends a lot of time sleeping -- and won't do anything unless the new global variable "event_scheduler" is set t ......
mysql数值范围
tinyint -128~127 0~255
smallint -32768~32767 0~65535
mediumint -8388608~8388607 0~16777215
int -2147483648~2147483647 0~4294967295
bigint -9223372036854775808~9223372036854775807 0~18446744073709551615
java中
byte ......
/**********************by garcon1986***************************************/
错误代码如下:
#1045 - Access denied for user 'root'@'localhost' (using password: YES)
$cd /etc/mysql
$mysql -u root -p
出现错误#1045
尝试了很多方法后,在网络上找到了解决方法。
$cd /etc/mysql
$gedit debian.cnf
找到 ......
先按照下面的表结构创建mysql_order_by_test数据表,我们用实例一点一点告诉你,MySQL order by的用法。
ORDER BY uid ASC
按照uid正序查询数据,也就是按照uid从小到大排列
ORDER BY uid DESC
按照uid逆序查询数据,也就是按照uid从大到小排列
我们来看
SELECT * from mysql_order_by_test OR ......
1.DATE_FORMAT('2010-05-15 15:47:36','%H:%i:%s') -> 结果:15:47:36
将日期格式根据条件不同转换成所需要的日期、时间格式
2.timediff('23:40:00', ' 18:30:00') -> 结果:05:10:00
......