Hallo alle zusammen ..Create-Methode in WebService (JAX-WS) Daten zu MySQL DB
Ich bin neu in Web-Service einfachen Web-Service (JAX-WS) zu schaffen, so versucht senden an Glass Fish Server 4.1.1, dieser Dienst sendet Daten an MySQL-Datenbank wie this, aber ich bekomme this Fehler, warum ich nicht weiß!?!?
MEIN CODES:
package com.me.coder;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
/**
*
* @author MacbookPro
*/
@WebService(serviceName = "GetWriteToDB")
public class GetWriteToDB {
/**
* Web service operation
*/
@WebMethod(operationName = "sendToDb")
public void sendToDb(@WebParam(name = "id") int id, @WebParam(name = "name") String name, @WebParam(name = "location") double location, @WebParam(name = "date") String date) {
String host = "jdbc:mysql://localhost/onurDB";
String user = "onur";
String pass = "onurdb958";
try(Connection conn = DriverManager.getConnection(host,user,pass);
Statement smt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
){
String SQL = "INSERT INTO `GoogleLoc`(`ID`, `NAME`, `LOCATION`, `DATE`) VALUES ('" + id + "','" + name + "','"+ location + "','" + date + "')";
smt.executeUpdate(SQL);
}catch(SQLException ex){
System.out.println("SQLException : " + ex);
}
}
}
Zur Kontrolle versuchten gleiche Codes in Java SE-Klasse funktionierte perfekt. So:
package send;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
*
* @author MacbookPro
*/
public class Send {
/**
* @param args the command line arguments
*/
private static String name,date;
private static int location,id;
public static void main(String[] args) throws IOException {
String host = "jdbc:mysql://localhost/onurDB";
String user = "onur";
String pass = "onurdb958";
try(Connection conn = DriverManager.getConnection(host,user,pass);
Statement smt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
){
insertData(smt);
}catch(SQLException ex){
System.out.println("SQLException : " + ex);
}
}
private static void insertData(Statement smt) throws SQLException, IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter ID : ");
String id = bf.readLine();
System.out.print("Enter Name : ");
String name = bf.readLine();
System.out.print("Enter Location : ");
String location = bf.readLine();
System.out.print("Enter Date : ");
String date = bf.readLine();
String sql;
sql = "INSERT INTO `GoogleLoc`(`ID`, `NAME`, `LOCATION`, `DATE`) VALUES ('" + id + "','" + name + "','"
+ location + "','" + date + "')";
smt.executeUpdate(sql);
System.out.println("Success! data inserted.");
}
}
ich meine Schuld in @WebMethod
Jemand kann mir bitte helfen vorstellen kann ???
Vielen Dank für alle ..
in Ihrem Screenshot, haben wir nicht das Ende des Stacktrace. – davidxxx
@davidhxxx Es zeigt nicht viel mehr als ... –