Java Interface for postgres database

Поиск
Список
Период
Сортировка
Искать

Java Interface for postgres database

От:
"suhail sarwar" <sarwar@postmaster.co.uk>
Дата:
Hi

I am trying to build a java front end to my postgres database. I have the database, psql and jdbc setup correctly and have made various tables but I need to make a front end for data input and retreival. 

I am thinking of having a java program that asks a series of questions and inputs the details into the correct part of the DB and once finished sends back an integer depending on the values input to the java program.

The problem is that I don't know how to use sql commands within a java program and how to send back values from the database to the java program. Does anyone know this?

Any help much appreciated

Regards

Re: Java Interface for postgres database

От:
Poul Kristensen <bcc5226@vip.cybercity.dk>
Дата:
import java.io.*; import java.util.Enumeration; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; import java.net.*; public class testservlet extends HttpServlet{ Connection theConnection; private ServletConfig config; public void init(ServletConfig config) throws ServletException{ this.config=config; } public void service (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { HttpSession session = req.getSession(true); res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println(""); out.println(""); out.println(""); out.println("

List of E-mail addresses."); out.println("

"); out.println("

"); out.println("
"); out.println("kolonne1"); out.println("kolonne2"); out.println("kolonne3
"); try{ //Loading Sun's JDBC ODBC Driver Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //Class.forName("postgresql.Driver"); //Connect to emaildb Data source theConnection = DriverManager.getConnection("jdbc:odbc:pg"); Statement theStatement=theConnection.createStatement(); ResultSet theResult=theStatement.executeQuery("select * from pstillinger where OnlineFra <= current.timestamp and OnlineTil >= current.timestamp"); //Select all records from emaillists table. //Fetch all the records and print in table while(theResult.next()){ out.println(); out.println("
"); out.println("" + theResult.getString(2) + ""); out.println("" + theResult.getString(3) + ""); out.println("" + theResult.getString(4) + ""); String s=theResult.getString(5); out.println("" + s + ">"); out.println("
"); } theResult.close();//Close the result set theStatement.close();//Close statement theConnection.close(); //Close database Connection }catch(Exception e){ out.println(e.getMessage());//Print trapped error. } out.println("
"); out.println("

 "); } public void destroy(){ } }

FAQ