Advertisement
Guest User

Untitled

a guest
Mar 12th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. Create database readers;
  2. Use readers;
  3.  
  4. CREATE TABLE reader
  5. (
  6. Name varchar(265),
  7. Surname varchar(255),
  8. City varchar(255),
  9. Capital varchar(255)
  10. );
  11.  
  12. Class.forName("com.mysql.jdbc.Driver");
  13.  
  14. //Connect to DB server
  15. Connection connection =
  16. DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/?user=root/autoReconnect=true&useSSL=false","root","password");
  17.  
  18. System.out.println("Connected to MySQL");
  19.  
  20. //Create Prepared Statement
  21. PreparedStatement statement =
  22. connection.prepareStatement("insert into readers (Name,Surname,City,Capital) values(?,?,?,?)");
  23.  
  24. Connected to MySQL
  25. java.sql.SQLException: No database selected
  26. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
  27. at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
  28. at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
  29. at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
  30. at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
  31. at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551)
  32. at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
  33. at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
  34. at edu.sabanciuniv.ReadWriteThread.run(ReadWriteThread.java:57)
  35.  
  36. jdbc:mysql://[host1][:port1][,[host2][:port2]]...[/[database]] [?propertyName1=propertyValue1[&propertyName2=propertyValue2]...]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement