mySql数据库连接
Class.forName("com.mySQL.jdbc.Driver");
String strUrl="jdbc:mysql://localhost:3306/stu?useUnicode=true&characterEncoding=GB2312";
String strUser="nuey";
String strPassword="password";
Connection conn=DriverManager.getConnection(strUrl, strUser, strPassword);
Statement rs=conn.createStatement();
String strSqlInsert="insert into tblScore (Name,Class,Score) values ('"+strName+"','"+strClass+"','"+strScore+"')";
int iResult=rs.executeUpdate(strSqlInsert);
if(iResult!=0)
{
out.println("添加成功!");
}
else
{
out.println("添加失败!");
}
导入jar包,然后怎么调试都是出现
java.lang.ClassNotFoundException: com.mySql.jdbc.Driver,
执行到第一步就出错,
上mysql网站下最新的驱动,还是不行,
郁闷之极,最后发现时大小写的问题,
第一句应该是
Class.forName("com.mysql.jdbc.Driver");
相关文档:
首先放置好jdbc驱动程序,在 java\jre6\lib\ext\下,java\jdk1.6\jre\lib等地方都放起来,因为不确定在哪里有用···
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost/DATABASENAME?user=USERNAME&password=PASSWORD&useUnicode=tru ......
今天在数据库中插入了中文,发现有的是乱码,有的不是,很是纳闷。
最后找到了解决办法:
打开 /etc/mysql/my.cnf
在[mysqld]和[client]节下分别添加:
default-character-set = utf8
然后重新启动mysql,需要注意的是,对修改以前创建的数据库来说,他的字符集还是原来的,所以还是会出现乱马,而新创建的数据 ......
一、MySQL 获得当前日期时间 函数
1.1 获得当前日期+时间(date + time)函数:now()
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2008-08-08 22:20:46 |
+---------------------+
除了 now() 函数能获得当前的日期时间外,MySQL 中还有下面的函数:
current_tim ......
一.先看一些最简单的例子
例子
Table A
aid adate
1 a1
2 a2
3 a3
TableB
bid bdate
1 b1
2 b2
4 b4
两个表a,b相连接,要取 ......
mysql 数据库默认的连接只能在本机连接,远程连接必须授权。
代码: 全选
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%'IDENTIFIED
BY 'mypassword' WITH GRANT
OPTION;如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用
mypassword作为密码
代码: GRANT ALL PR ......