Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Create database readers;
- Use readers;
- CREATE TABLE reader
- (
- Name varchar(265),
- Surname varchar(255),
- City varchar(255),
- Capital varchar(255)
- );
- Class.forName("com.mysql.jdbc.Driver");
- //Connect to DB server
- Connection connection =
- DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/?user=root/autoReconnect=true&useSSL=false","root","password");
- System.out.println("Connected to MySQL");
- //Create Prepared Statement
- PreparedStatement statement =
- connection.prepareStatement("insert into readers (Name,Surname,City,Capital) values(?,?,?,?)");
- Connected to MySQL
- java.sql.SQLException: No database selected
- at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
- at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
- at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
- at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
- at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
- at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551)
- at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
- at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
- at edu.sabanciuniv.ReadWriteThread.run(ReadWriteThread.java:57)
- jdbc:mysql://[host1][:port1][,[host2][:port2]]...[/[database]] [?propertyName1=propertyValue1[&propertyName2=propertyValue2]...]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement