Results 1 to 3 of 3
  1. #1
    mrmodest is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Unhappy Java client/server/mysql

    Alright so I have a project where I must use a jbutton in my gui/client to send a request to a server which contains mysql code and then that code is sent to my table in mysql. The server connects fine to my client, but my commands arent being issued because my table isn't being added to in mysql. Take a look at the code here and maybe you guys can help me out.

    in the client-----

    Socket s = new Socket("url",port);
    InputStream instream = s.getInputStream();
    OutputStream outstream = s.getOutputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(instream));
    PrintWriter out = new PrintWriter(outstream);

    private void addvideobuttonActionPerformed(java.awt.event.Actio nEvent evt) {

    if (addvideobutton.isSelected()){
    System.out.println("test");
    String a1 = videocodeadd.getText();
    String a2 = videotitleadd.getText();
    String a3 = videoyearadd.getText();
    String a4 = videogenraadd.getText();
    String a5 = videoactoradd.getText();
    String a6 = videoactressadd.getText();
    String a = (a1 + "," + "'" + a2 + "," + "'" + a3 + "," + "'" + a4 + "," + "'" + a5 + "," + "'" + a6 + "'");

    String query = "addvideo";
    out.write(query);
    out.write(a);
    out.flush();
    System.out.println("test");


    }
    }

    -----------------------
    in my server--------
    String username = "name";
    String password = "passwrd";
    String url = "url for mysql database";
    String driver = "com.mysql.jdbc.Driver";


    Scanner in;
    PrintWriter out;

    while (true){
    ServerSocket server = new ServerSocket(port);
    Class.forName(driver).newInstance();
    Connection conn = DriverManager.getConnection(url, username, password);
    Statement statement = conn.createStatement();

    System.out.println("waiting for connection");
    Socket s = server.accept();
    System.out.println("connection accepted"); // it prints this when my client starts
    System.out.println("running..."); // it prints this when my client starts
    String command = in.next();
    System.out.println("the command was " + command);// this is never printer...


    in = new Scanner(s.getInputStream());
    out = new PrintWriter(s.getOutputStream());

    try{
    if (in.next().equals("addvideo")){
    System.out.println("innext = addvideo");
    String a = in.next();
    System.out.println("a is in.next");
    String addvideo = "INSERT INTO Videos values(" + a;
    ResultSet rst = statement.executeQuery(addvideo);
    System.out.println("addvideo has become sql code");
    out.write(addvideo);
    System.out.println("printed to database");
    out.flush();

    }
    }finally{
    s.close();
    }

    --------------------
    and nothing happens to my database, please help... not alot of time. Thanks!

  2. #2
    mrmodest is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default please help

    I am still waiting for a response here if anyone knows anything, did I do something wrong in my post?

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Use executeUpdate for inserts instead of executeQuery then read the return value of executeUpdate and print it out to find out what happened.

Similar Threads

  1. java client-server jmf
    By grayhat555 in forum Networking
    Replies: 0
    Last Post: 03-16-2011, 02:02 AM
  2. Java Server/C Client
    By FallenBlade in forum Networking
    Replies: 13
    Last Post: 03-10-2011, 11:22 PM
  3. Replies: 2
    Last Post: 09-24-2010, 11:31 AM
  4. java server and c client ?????????
    By biebo in forum Networking
    Replies: 7
    Last Post: 07-24-2010, 04:35 AM
  5. Replies: 2
    Last Post: 11-10-2009, 04:29 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •