bash-3.00# uname -a
SunOS unknown 5.10 Generic_127128-11 i86pc i386 i86pc
bash-3.00# cat ./user.sql
use mysql;
DELETE FROM user WHERE user = '';
DROP USER newuser;
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'%' IDENTIFIED BY 'pwd';
FLUSH PRIVILEGES;
bash-3.00# mysql -u root -p < ./user.sql
Enter password:
bash-3.00# cat MySQLJdbc.java
import java.sql.*;
class MySQLJdbc
{
public static void main(String args[])
{
Connection con = null;
Statement stmt = null;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql:///test","newuser", "pwd");
//con = DriverManager.getConnection("jdbc:mysql:///test","newuser", "");
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1");
while (rs.next()) {
System.out.println(rs.getString(1));
}
rs.close();
stmt.close();
con.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
bash-3.00# javac MySQLJdbc.java
bash-3.00# java -cp .:mysql-connector-java-5.1.6.jar MySQLJdbc
1
bash-3.00# vi MySQLJdbc.java
~
~
:q
bash-3.00# cat MySQLJdbc.java
import java.sql.*;
class MySQLJdbc
{
public static void main(String args[])
{
Connection con = null;
Statement stmt = null;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
//con = DriverManager.getConnection("jdbc:mysql:///test","newuser", "pwd");
con = DriverManager.getConnection("jdbc:mysql:///test","newuser", "");
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1");
while (rs.next()) {
System.out.println(rs.getString(1));
}
rs.close();
stmt.close();
con.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
bash-3.00# javac MySQLJdbc.java
bash-3.00# java -cp .:mysql-connector-java-5.1.6.jar MySQLJdbc
java.sql.SQLException: Access denied for user 'newuser'@'localhost' (using password: NO)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:910)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3923)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1273)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at MySQLJdbc.main(MySQLJdbc.java:13)