JDBC Problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

JDBC Problem

Java Code: import java.sql.*; public class Prog { public static void main(String[] args) throws ClassNotFoundException, SQLException { String url="jdbc:mysql://localhost:3306/emp"; String uname = "root"; String pass = "root123"; String query = "select name from student where roll = 3;"; Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection(url,uname,pass); Statement st = con.createStatement(); ResultSet rs= st.executeQuery(query); String nams = rs.getString("name"); System.out.print(nams); st.close(); con.close(); } } MySQL Table: mysql> select * from student; roll name 1 Agnibha 2 Samrat 3 Zanjo ERROR: Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. Wed Jun 06 11:12:46 IST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Exception in thread "main" java.sql.SQLException: Before start of result set at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:87) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:61) at com.mysql.cj.jdbc.result.ResultSetImpl.checkRowPos(ResultSetImpl.java:506) at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:869) at com.mysql.c

6th Jun 2018, 5:47 AM
Agnibha Chakraborty
Agnibha Chakraborty - avatar
3 Answers
+ 2
i think you should change this Class.forName("com.mysql.jdbc.Driver"); to Class.forName("com.mysql.cj.jdbc.Driver");
6th Jun 2018, 7:43 AM
AYUSH GUPTA
AYUSH GUPTA - avatar
+ 1
That's a warning just. Check the error part.
6th Jun 2018, 7:59 AM
Agnibha Chakraborty
Agnibha Chakraborty - avatar