我的类是下面这样的,并且Mysql4.1已经装好了,我还可以通过[MySQL Command Line Client]登陆!
import java.sql.*;
public class ConnMysql
{
public static void main(String[] abc) throws ClassNotFoundException,SQLException,
InstantiationException,IllegalAccessException
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/3306/samp_db?user=root&password=root123&useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from users where name='may'";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {
System.out.println("this is a username--->"+rs.getString(1));
System.out.println("this is a userpass--->"+rs.getString(2));
}
rs.close();
stmt.close();
conn.close();
}}
import java.sql.*;
public class ConnMysql
{
public static void main(String[] abc) throws ClassNotFoundException,SQLException,
InstantiationException,IllegalAccessException
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/3306/samp_db?user=root&password=root123&useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from users where name='may'";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {
System.out.println("this is a username--->"+rs.getString(1));
System.out.println("this is a userpass--->"+rs.getString(2));
}
rs.close();
stmt.close();
conn.close();
}}
解决方案 »
- mysql error
- 我在C++中包含mysql.h头文件,编译时却找不到my_socket类型,是怎以回事啊?
- 数据量过大如何select
- 如何安装PostgreSQL OLE DB 驱动
- 在一个服务器上可以最多建立多少个数据库阿,每个数据库中有多少个表阿?
- MySQL中update操作的影响行数row_count问题
- mysqldump着急阿.....在线!!!!!!!!!!!
- 求找茬。。。
- show full processlist 出现大量的mysql-connector-java-
- mysql亿级数据条表加索引报1034错误
- 求助:mysql无法启动!
- 从mssql移值到mysql问题?
Class.forName("org.gjt.mm.mysql.Driver") 可以尝试换成
Class.forName("com.mysql.jdbc.Driver")