English 中文(简体)
Java Cookie/Session - Problem - phpmyadmin
原标题:Java Cookie/Session - Problem - phpmyadmin

hi guys i 想把一种工具编成法典,与Sandreamyadmin互动。 我想设立一个新的表格。 为此,需要ok具和安全。 我已经做了两件事。 我的问题是 co子,与这些库克群岛一道打开新的URLConnection。 我的要求也得到了证明。 但是,每当我这样做时,我就回答说,我的Query是空洞的,如果乌能拿到这个Error ur token,就是无效的。 一种无效的象征性意思是,在新的关系中,ur的 t子被置于非常好的位置,因此与以前没有相同的届会。 什么是错的,解决该问题的任何想法?

这里是我的法典(很奇怪,但只是为了测试目的)。

import java.io.*;
import java.net.*;
import java.util.List;

public class connect {

 public void connectto() throws IOException{
     URLConnection connection = new URL("http://localhost/phpmyadmin/index.php").openConnection();
     List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
     connection.connect();
     InputStream response = connection.getInputStream();
     BufferedReader br = new BufferedReader(new InputStreamReader(response));
     String line;
     String token = "";
     while((line = br.readLine())!= null){
         System.out.println(line);
     if (line.contains("var token = ")){
         System.out.println("hit");
          token = "&token=" + line.substring(line.indexOf("var token =  ") + "var token =  ".length()).substring(0, line.substring(line.indexOf("var token =  ") + "var token =  ".length()).indexOf(" ;"));
     }

     }
     System.out.println(token);

     String url = URLEncoder.encode("db=mysql&sql_query=CREATE TABLE testtable(testtable TEXT);" + token, "UTF-8");


     connection = new URL("http://localhost/phpmyadmin/sql.php?" + url).openConnection();
     connection.setDoOutput(true);
     for (String cookie : cookies) {
         System.out.println(cookie.split(";", 2)[0]);
         connection.addRequestProperty("Cookie", cookie.split(";", 2)[0]);
     }
     connection.connect();
     response = connection.getInputStream();
     br = new BufferedReader(new InputStreamReader(response));
     line = "";
     while((line = br.readLine())!= null){
     System.out.println(line);
     }

     }
 }
问题回答

My apologies if I misunderstood your issue but why are you forcing the request through phpMyAdmin? The point of phpMyAdmin is to provide a UI to people to work with their MySQL database. If you want to interact with the MySQL database you should be opening a connection directly to the database and executing statements in the java code.

Again, please excuse my ignorance if this is unfeasable for you but if you must work through phpMyAdmin instead of a direct connection between Java and your DB please provide more information.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签