Skip to content
Snippets Groups Projects
Commit 142c6117 authored by Ulung32's avatar Ulung32
Browse files

chore: connecting to mysql (still error), lanjutin dew

parent d8eab7e1
Branches
Tags
No related merge requests found
...@@ -4,3 +4,4 @@ MYSQL_USERNAME=user ...@@ -4,3 +4,4 @@ MYSQL_USERNAME=user
MYSQL_DATABASE=tubes-db MYSQL_DATABASE=tubes-db
MYSQL_PASSWORD=rootpw MYSQL_PASSWORD=rootpw
MYSQL_ROOT_PASSWORD=rootpw MYSQL_ROOT_PASSWORD=rootpw
MYSQL_URL=jdbc:mysql://localhost:6307/tubes-db
import javax.xml.ws.Endpoint; import javax.xml.ws.Endpoint;
import repo.repository;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
Endpoint.publish("http://0.0.0.0:6001/ws/hello", new ws.TestWSImpl()); Endpoint.publish("http://0.0.0.0:6001/ws/hello", new ws.TestWSImpl());
System.out.println("Service berhasil di publish"); System.out.println("Service berhasil di publish");
repository repo = new repository();
System.out.println(repo.getConnection());
} }
} }
\ No newline at end of file
package middleware; // package middleware;
import javax.xml.ws.handler.soap.SOAPHandler; // import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext; // import javax.xml.ws.handler.soap.SOAPMessageContext;
public class Middleware implements SOAPHandler<SOAPMessageContext>{ // public class Middleware implements SOAPHandler<SOAPMessageContext>{
//yang perlu kerjain untuk semua servis contoh : cek api key dan logging // //yang perlu kerjain untuk semua servis contoh : cek api key dan logging
} // }
package repo; package repo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class repository { public class repository {
//ini gunanya buat ngequery di db //ini gunanya buat ngequery di db
//konekin db ntar di constructor ini //konekin db ntar di constructor ini
//bikin anak2nya ntar //bikin anak2nya ntar
private Connection connection;
public repository() {
// System.out.println(System.getenv("MYSQL_USERNAME"));
try {
String url = System.getenv("MYSQL_URL");
String username = System.getenv("MYSQL_USERNAME");
String password = System.getenv("MYSQL_PASSWORD");
System.out.println("ini test") ;
System.out.println(url);
System.out.println(username);
System.out.println(password);
Class.forName("com.mysql.jdbc.Driver");
System.out.println("ini test2") ;
this.connection = DriverManager.getConnection(url, username, password);
System.out.println("Koneksi ke MySQL berhasil!");
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
System.err.println("Gagal terhubung ke MySQL");
}
}
public Connection getConnection(){
return this.connection;
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment