Home Frequently Asked Questions SQL

 

 

This page answers common questions related to the SQL services offered at CSIS.


 

Please note that there are many variants of SQL. You should always consult product-specific documentation when working with SQL.

 


 

Questions

 
 
 
 
 
 
 
 
 
 
 

 


 

Q: How do I connect to an Oracle Database server?

 

A: There are actually many ways to connect to an Oracle database but at Pace we use sqlplus. If you are using the oracle database associated with vulcan.seidenberg.pace.edu you will connect to the oracle database in the following manner:


 $ sqlplus username/password@apollo
	  

Q: How do I connect to a MySQL database?

 

A: There are many ways to connect to a MySQL database but at Pace we use the standard utility mysql. If you are using the MySQL database associated with vulcan.seidenberg.pace.edu, you will connect to the MySQL database in the following manner:


	  $ mysql -u username -p

	  

After you have successfully logged in, you must connect to a specific database instance. If you are using the MySQL database associated with vulcan.seidenberg.pace.edu, type the following:


	  mysql> connect db_instance 

	  


** Where db_instance is the database instance assigned to you by your professor.


Q: What do I need to know to connect to an oracle database from my java program?


A: There are six things that you need to know to connect to an oracle database from a program:
 
  • DRIVER
  • IP ADDRESS
  • PORT NUMBER: The well-known port for oracle is 1521
  • ORACLE INSTANCE: The default at Pace is ORA1
  • USERNAME as given by your Professor
  • PASSWORD as given by your Professor
   

Therefore, you will use a connection string similar to the following to connect to the database server associated with http://vulcan.seidenberg.pace.edu

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
String dbURL="jdbc:oracle:thin:@apollo:1521:ORA1";
Connection conn=DriverManager.getConnection(dbURL,"USERNAME","PASSWORD");
	  
Sample Java File
      import javax.servlet.http.*;
      import javax.servlet.*;
      import java.io.*;
      import java.sql.*;
      import java.math.*;
      public class delphi extends HttpServlet{
        public void doGet(HttpServletRequest req, HttpServletResponse res) throws 
          ServletException, IOException{
               PrintWriter out;
               out = res.getWriter();
               res.setContentType("text/html");
               try{
                   DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                   String dbURL="jdbc:oracle:thin:@apollo:1521:ORA1";
                   Connection conn=DriverManager.getConnection(dbURL,"username","password");
                   Statement stmt=conn.createStatement();
                   ResultSet rset=stmt.executeQuery("SELECT Name,Notes from people");
                   out.println("<HTML><HEAD><TITLE>DB SERVLET</TITLE></HEAD>");
                   out.println("<BODY>");
                   while(rset.next()){
                     out.println(rset.getString("Name")+" "+rset.getString("Notes"));
                     out.println("<BR>");
                   }
                   rset.close();
                   stmt.close();
                   conn.close();
                }catch(Exception e){}
                out.println("<H1>I added this information!</H1>");
                out.println("<BR><H1>I added this line too!</H1>");
                out.println("</BODY></HTML>");
                out.close();
        }
    }
    

Q: How do I change my password in the Oracle server?

 

A: When logged into the Oracle server, type the following:
$ >password

Q: How do I create a table in SQL?

 

A:  
  create table people (name varchar(20), notes varchar(20));

 

Q: How do I insert data into a table in SQL?

 

A:  
  insert into people values ('Tom','Tom works at Pace');

 

Q: How do I select data from a table in SQL?

 

A:  
  select * from people;

 

Q: How do I update data in a table in SQL?

 

A:  
 

update people

set name = 'Thomas',

notes = 'Thomas works at Pace'

where name = 'Tom';

 

Q: How do I delete data from a table in SQL?

 

A:  
  delete people where name = 'Tom';

 

Q: How do I remove a table in SQL?

 

A:  
  drop table people;

 

Q: Where can I go to learn more about SQL?

 

A: There is an overwhelming amount of material related to SQL.

Here is an online tutorial that I find helpful for the basics.

You should search for materials that are appropriate for your goals and projects.
Here are some places to start:

Books

Search amazon.com for books about SQL

Online Resources

Search google for SQL tutorials

Oracle 8i SQL Reference (pdf)

Oracle 8i SQLPLUS Reference (pdf)



If you have any material (questions or answers) that may be useful here, send them to

csis@pace.edu