Mageia Bugzilla – Attachment 6809 Details for
Bug 16070
mysql-connector-java new security issue CVE-2015-2575
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
java code written to test
Mariadb_Connect.java (text/x-java), 3.26 KB, created by
Brian Rockwell
on 2015-07-04 01:41:37 CEST
(
hide
)
Description:
java code written to test
Filename:
MIME Type:
Creator:
Brian Rockwell
Created:
2015-07-04 01:41:37 CEST
Size:
3.26 KB
patch
obsolete
> > >import java.sql.DriverManager; >import java.sql.ResultSet; >import java.sql.SQLException; > >import com.mysql.jdbc.Connection; > > >public class Mariadb_Connect { > > public static void main(String[] args) { > Connection con = null; > try { > Class.forName("com.mysql.jdbc.Driver").newInstance(); > //The parameters are connection, user-id, user-password (I have maria running in default) > con = (Connection) DriverManager.getConnection("jdbc:mysql:///test", > "", ""); > if (!con.isClosed()) { > System.out.println("Successfully connected to " > + "MySQL server using TCP/IP..."); > create_tables(con); > read_books(con); > drop_books(con); > } > } catch (Exception e) { > e.printStackTrace(); > System.out.println("Exception: " + e.getMessage()); > } finally { > try { > if (con != null) { > System.out.println("Close the database connection"); > con.close(); > } > } catch (SQLException e) { > } > } > > } > > private static void create_tables(Connection lvcon) { > java.sql.PreparedStatement qry; > try { > qry = lvcon.prepareStatement("CREATE DATABASE IF NOT EXISTS test"); > qry.execute(); > > System.out.println("Database test checked"); > qry = lvcon.prepareStatement("USE test"); > qry.execute(); > System.out.println("Changed to test database"); > > String tbls="CREATE TABLE IF NOT EXISTS books (BookID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, Title VARCHAR(100) NOT NULL, SeriesID INT, AuthorID INT)"; > qry=lvcon.prepareStatement(tbls); > qry.execute(); > System.out.println("Table books created"); > > String insertlist="INSERT INTO books (Title,SeriesID,AuthorID) VALUES('The Fellowship of the Ring',1,1), ('The Two Towers',1,1), ('The Return of the King',1,1), ('The Sum of All Men',2,2),('Brotherhood of the Wolf',2,2), ('Wizardborn',2,2), ('The Hobbbit',0,1)"; > qry=lvcon.prepareStatement(insertlist); > qry.execute(); > System.out.println("Rows insertered into books table"); > > } catch (SQLException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > > } > > private static void read_books(Connection lvcon) { > java.sql.PreparedStatement qry; > ResultSet lvrs; > > try { > System.err.println("---------------------------------"); > System.err.println("Now listing the titles from books"); > System.err.println("---------------------------------"); > qry=lvcon.prepareStatement("select * from books"); > lvrs = qry.executeQuery(); > while (lvrs.next()) { > System.out.println(lvrs.getString(1) + " " + lvrs.getString(2)); > > } > System.err.println("---------------------------------"); > System.err.println(""); > > } catch (SQLException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > } > > private static void drop_books(Connection lvcon) { > java.sql.PreparedStatement qry; > > try { > qry=lvcon.prepareStatement("drop table books"); > qry.execute(); > System.out.println("dropped the books table"); > > } catch (SQLException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > } > >} >
import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import com.mysql.jdbc.Connection; public class Mariadb_Connect { public static void main(String[] args) { Connection con = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); //The parameters are connection, user-id, user-password (I have maria running in default) con = (Connection) DriverManager.getConnection("jdbc:mysql:///test", "", ""); if (!con.isClosed()) { System.out.println("Successfully connected to " + "MySQL server using TCP/IP..."); create_tables(con); read_books(con); drop_books(con); } } catch (Exception e) { e.printStackTrace(); System.out.println("Exception: " + e.getMessage()); } finally { try { if (con != null) { System.out.println("Close the database connection"); con.close(); } } catch (SQLException e) { } } } private static void create_tables(Connection lvcon) { java.sql.PreparedStatement qry; try { qry = lvcon.prepareStatement("CREATE DATABASE IF NOT EXISTS test"); qry.execute(); System.out.println("Database test checked"); qry = lvcon.prepareStatement("USE test"); qry.execute(); System.out.println("Changed to test database"); String tbls="CREATE TABLE IF NOT EXISTS books (BookID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, Title VARCHAR(100) NOT NULL, SeriesID INT, AuthorID INT)"; qry=lvcon.prepareStatement(tbls); qry.execute(); System.out.println("Table books created"); String insertlist="INSERT INTO books (Title,SeriesID,AuthorID) VALUES('The Fellowship of the Ring',1,1), ('The Two Towers',1,1), ('The Return of the King',1,1), ('The Sum of All Men',2,2),('Brotherhood of the Wolf',2,2), ('Wizardborn',2,2), ('The Hobbbit',0,1)"; qry=lvcon.prepareStatement(insertlist); qry.execute(); System.out.println("Rows insertered into books table"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private static void read_books(Connection lvcon) { java.sql.PreparedStatement qry; ResultSet lvrs; try { System.err.println("---------------------------------"); System.err.println("Now listing the titles from books"); System.err.println("---------------------------------"); qry=lvcon.prepareStatement("select * from books"); lvrs = qry.executeQuery(); while (lvrs.next()) { System.out.println(lvrs.getString(1) + " " + lvrs.getString(2)); } System.err.println("---------------------------------"); System.err.println(""); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private static void drop_books(Connection lvcon) { java.sql.PreparedStatement qry; try { qry=lvcon.prepareStatement("drop table books"); qry.execute(); System.out.println("dropped the books table"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
View Attachment As Raw
Actions:
View
Attachments on
bug 16070
: 6809