Java.Help

  • Автор теми AkeL.php
  • Дата створення
A

AkeL.php

Guest
Ответ: Java.Help

Сделал так.
PHP:
out.println("before");
con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/test","newuser", "");
out.println("after");
"before" выводит
"after" нет :)
Станно, что даже никаких ошибок не показывает.
 

daoway

кот Шрёдингера
Ответ: Java.Help

Сделал так.
Код:
out.println("before");
con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/test",
[COLOR="Red"]"newuser", "";[/COLOR]);
out.println("after");
"before" выводит
"after" нет :)
Станно, что даже никаких ошибок не показывает.
Мож newuser-у ещё и пароль прописать ?
 
A

AkeL.php

Guest
Ответ: Java.Help

Подключался с обычного java-приложения. Без пароля, подключился.
Да и консоли соединялся с mysql, без пароля :). А jsp никак...
 

daoway

кот Шрёдингера
Ответ: Java.Help

Подключался с обычного java-приложения. Без пароля, подключился.
Да и консоли соединялся с mysql, без пароля :). А jsp никак...
PHP:
C:\>mysql -u newuser
ERROR 1045 (28000): Access denied for user 'newuser'@'localhost' (using password: NO)

C:\>mysql -u newuser -p
Enter password: ***
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
И ещё
PHP:
C:\temp\Ackel>javac MySQLJdbc.java
C:\temp\Ackel>java -cp .;mysql-connector-java-5.1.6.jar MySQLJdbc
1

C:\temp\Ackel>javac MySQLJdbc.java
C:\temp\Ackel>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.JDBC4Connection.<init>(JDBC4Connection.java:46)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at MySQLJdbc.main(MySQLJdbc.java:13)
В первом случае с паролем - во втором - без
Код:
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();
      	     }
    }    
}
 
Останнє редагування:
A

AkeL.php

Guest
Ответ: Java.Help

Хм..
Код:
akel@akel-desktop:~$ mysql -u newuser
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.0.51a-3ubuntu5.1 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
PHP:
akel@akel-desktop:~/JAVA/Mysql$ sudo -s CLASSPATH=$CLASSPATH:/usr/share/java/mysql.jar
root@akel-desktop:~/JAVA/Mysql# javac Connect.java
root@akel-desktop:~/JAVA/Mysql# java Connect
_2
number___INT
name___VARCHAR
Код:
import java.sql.*; 
import java.io.*; 

class Connect{
	 public static void main(String args[]) throws Exception {
        Connection con = null;
        Statement stmt=null;
 try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      con = DriverManager.getConnection("jdbc:mysql:///test","newuser", "");
      stmt = con.createStatement();
	ResultSet rs = stmt.executeQuery("SELECT * FROM photos");
       ResultSetMetaData md=rs.getMetaData();
         int col=md.getColumnCount();
         System.out.println("_" + col);
         for(int i=1; i<= col; i++){
             System.out.println(md.getColumnName(i)+"___"+md.getColumnTypeName(i));
         }
       stmt.close();
       con.close(); 
    }  catch (Exception e) {
        e.printStackTrace();
      }   
    }
}
 

daoway

кот Шрёдингера
Ответ: Java.Help

PHP:
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)
 
A

AkeL.php

Guest
Ответ: Java.Help

Есть. Теперь работает без пароля.

А с jsp та же история.

PHP:
21: 	 		
22:       		Class.forName("com.mysql.jdbc.Driver").newInstance();
23:       		out.println("before");
24:       		     con = DriverManager.getConnection("jdbc:mysql:///test","newuser", "pwd");
25:       		out.println("after");
26:      		stmt = con.createStatement();
27: 			ResultSet rs = stmt.executeQuery("SELECT * FROM photos");


Stacktrace:
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	sun.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	java.lang.reflect.Method.invoke(Method.java:597)
	org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
	java.security.AccessController.doPrivileged(Native Method)
	javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
	org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
	org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)

root cause

javax.servlet.ServletException: Communications link failure

Last packet sent to the server was 0 ms ago.
	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
	org.apache.jasper.runtime.PageContextImpl.access$11(PageContextImpl.java:779)
	org.apache.jasper.runtime.PageContextImpl$12.run(PageContextImpl.java:761)
	java.security.AccessController.doPrivileged(Native Method)
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:759)
	org.apache.jsp.blog.index_jsp._jspService(index_jsp.java:132)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	sun.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	java.lang.reflect.Method.invoke(Method.java:597)
	org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
	java.security.AccessController.doPrivileged(Native Method)
	javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
	org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
	org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)

root cause

com.mysql.jdbc.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.
	com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1070)
	com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2104)
	com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)
	com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
	com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
	java.sql.DriverManager.getConnection(DriverManager.java:582)
	java.sql.DriverManager.getConnection(DriverManager.java:185)
	org.apache.jsp.blog.index_jsp._jspService(index_jsp.java:67)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	sun.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	java.lang.reflect.Method.invoke(Method.java:597)
	org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
	java.security.AccessController.doPrivileged(Native Method)
	javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
	org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
	org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)

root cause

java.net.SocketException: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)
	com.mysql.jdbc.StandardSocketFactory.unwrapExceptionToProperClassAndThrowIt(StandardSocketFactory.java:407)
	com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:268)
	com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:277)
	com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2030)
	com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)
	com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
	com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
	java.sql.DriverManager.getConnection(DriverManager.java:582)
	java.sql.DriverManager.getConnection(DriverManager.java:185)
	org.apache.jsp.blog.index_jsp._jspService(index_jsp.java:67)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	sun.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	java.lang.reflect.Method.invoke(Method.java:597)
	org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
	java.security.AccessController.doPrivileged(Native Method)
	javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
	org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
	org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
 

daoway

кот Шрёдингера
Ответ: Java.Help

Есть. Теперь работает без пароля.

А с jsp та же история.
Как так без пароля ?? Ты это в war-e деплоиш или нет ? Сервлет пробовал свой запустить ? Ты почитай как пакуются веб приложения на жаве, куда либы с классами ложить, что такое деплоймент.
 
A

AkeL.php

Guest
Ответ: Java.Help

И ещё.
Код:
akel@akel-desktop:~$ nmap localhost
]
Starting Nmap 4.53 ( http://insecure.org ) at 2008-07-04 19:50 EEST
Stats: 0:00:00 elapsed; 0 hosts completed (0 up), 0 undergoing Ping Scan
Ping Scan Timing: About 100.00% done; ETC: 19:50 (0:00:00 remaining)
Interesting ports on localhost (127.0.0.1):
Not shown: 1709 closed ports
PORT     STATE SERVICE
80/tcp   open  http
631/tcp  open  ipp
[B]3306/tcp open  mysql[/B]
6881/tcp open  bittorent-tracker
8009/tcp open  ajp13

Nmap done: 1 IP address (1 host up) scanned in 0.191 seconds
Добавил в /usr/share/tomcat5.5/conf/catalina.policy
Код:
grant codeBase "file:${catalina.home}/webapps/blog/-" {
      permission java.net.SocketPermission "*", "resolve";
      permission java.net.SocketPermission "*", "connect";
};
Но при рестарте tomcat'а эти данные почему -то удаляются...
 
Останнє редагування модератором:
Зверху