Posts

Showing posts with the label jdbc

| have added MySQL Connector to libraries , but still getting error 'java.lang.ClassNotFoundException: com.mysql.jdbc.driver' [duplicate]

| have added MySQL Connector to libraries , but still getting error 'java.lang.ClassNotFoundException: com.mysql.jdbc.driver' [duplicate] This question already has an answer here: import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; /** * Servlet implementation class LoginChek */ @WebServlet("/LoginChek") public class LoginChek extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public LoginChek() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequ...

springboot/jpa can't connect to mysql with username “@localhost” using password no?

springboot/jpa can't connect to mysql with username “@localhost” using password no? I'm trying to connect to MySQL database. persistent.xml <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="2.1"> <persistence-unit name="myApp"> <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <properties> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> <!-- TODO: Change file location to your H2 database ! --> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/myDB...

How to store retrieved data from mysql and display as a result for user's search in java

How to store retrieved data from mysql and display as a result for user's search in java try{ Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/customer"; String uName = "root"; String password = ""; // unsafe sharing password Connection con = DriverManager.getConnection(url, uName, password); String query = "select * from mansions"; PreparedStatement ps = con.prepareStatement(query); //ps.executeUpdate(); it wont accept query with select keyword ResultSet rs = ps.executeQuery(); String str = ""; while(rs.next()) System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getLong(3)+rs.getString(4)+" "+rs.getString(5)+" "+rs.getString(6)+" "+rs.getString(7)+" "+rs.getInt(8)+" "+rs.getString(9)+" "+rs.getString(10)); str = rs.getString(2); System.out...

Copying specific tables of a MySQL database to a MariaDB database in JDBC

Copying specific tables of a MySQL database to a MariaDB database in JDBC I am trying to create a Java programm that copies specific tables from a MySQL database on one server to a MariaDB on another. I know there is mysqldump but the purpose of the program is to be running on different machines, even if they don't habe mysql installed. What I created seems to work well, as the resulting SQL does look correct and executes for example when I connect to the MariaDB with HeidiSQL. But when I execute the sql using .executeQuery , I get an error as response that there is a problem with my SQL. .executeQuery The code is basically: import java.sql.* public class JdbcTest { Connection conn = null; Connection conn_2 = null; Statement stmt = null; Statement stmt_2 = null; //MySQL Class.forName("com.mysql.cj.jdbc.Driver"); //MariaDB Class.forName("org.mariadb.jdbc.Driver"); System.o...