Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package raizel;
- import java.sql.*;
- public class ConnectToDB
- {
- public boolean add(String name, String username, String password)
- {
- String url = "jdbc:mysql://localhost/practice";
- String userid = "root";
- String pass = "root";
- try {
- Class.forName("com.mysql.jdbc.Driver");
- }
- catch(java.lang.ClassNotFoundException e)
- { System.err.print("ClassNotFoundException: " + e.getMessage()); }
- try
- {
- Connection con = DriverManager.getConnection(url, userid, pass);
- Statement stmt;
- stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
- stmt.executeUpdate("Insert into account (name,username,password) values('"+name+"','"+username+"','"+password+"')");
- stmt.close();
- con.close();
- }
- catch(SQLException ex) { System.err.println("SQLException: " + ex.getMessage()); return false;}
- return true;
- }
- /*public String [] browse(String passToBrowse)
- {
- String returnValue[] = new String[3];
- String url = "jdbc:mysql://10.4.195.241/ceacwed";
- String userid = "ceacwed";
- String pass = "miyerkules";
- System.out.println(userid +" "+pass);
- try { Class.forName("com.mysql.jdbc.Driver"); }
- catch(java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: " + e.getMessage()); }
- try
- {
- Connection con = DriverManager.getConnection(url, userid, pass);
- Statement stmt;
- stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
- ResultSet rs = stmt.executeQuery("Select username from account where password = '"+passToBrowse+"'");
- rs.next();
- returnValue[0] = rs.getString("password");
- // returnValue[1] = rs.getString("address");
- // returnValue[2] = rs.getString("telephone");
- stmt.close();
- con.close();
- }
- catch(SQLException ex) { System.err.println("SQLException: " + ex.getMessage()); }
- return returnValue;
- }*/
- }
Add Comment
Please, Sign In to add comment