I tried to connect to database using java. In main function I have a following code:
String url = "jdbc:mysql://localhost:3306/";
String driver = "com.mysql.jdbc.Driver";
String dbname = "probna_bp";
Connection kon=DriverManager.getConnection(url+dbname, "root", "");
izraz.executeUpdate("insert into korisnici values(1, 'mujo', 'mujina');");
But, when I run this, it shows me exception:
com.mysql.jdbc.Driver is driver that I use to connect
What could be a problem?
I suspect that the driver's jar may not be on your classpath. You will need to place it on the classpath for this to work and how you do this will depend on how you are running your code. Are you using an IDE such as NetBeans or Eclipse or are you compiling and running on the command line?
Also, you'll want to reply to the helpful responses to your post from yesterday. Doing this will encourage others to help you in the future. Just a little suggestion.
Yes, that was a problem. I'm using Net Beans IDE. I just imported mysql-connector in project and it works.
Thank you very much for answer and for suggestion. I'm new to java
and this forums. so sorry for not replying :)