The Artima Developer Community
Sponsored Link

Java Answers Forum
Please help with java

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
chuck

Posts: 9
Nickname: chuckjava2
Registered: Jul, 2002

Please help with java Posted: Aug 5, 2002 12:14 PM
Reply to this message Reply
Advertisement
Please take a look at my while statement. I try to check for a table named StudentRecord. If the table already existed, just insert into it. If the table has not existed, create the table named StudentRecord, then insert into it. My codes are wrong. Please help. Thank you veyr much





import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import sun.jdbc.odbc.*;
import java.text.*;

public class Assign5th extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {



String p1, p2, p3, p4;
p1 =request.getParameter("param1");
p2 =request.getParameter("param2");
p3 =request.getParameter("param3");
p4 =request.getParameter("param4");

try{
ResultSet rs;
//Load drivers
new JdbcOdbcDriver();
String url = "jdbc:odbc:Sales";

//Connect to database
String user = "";
String password = "";
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();

//Create DatabaseMetaData object
DatabaseMetaData dbMetaData = con.getMetaData();

String[] tables ={"TABLE"};
rs = dbMetaData.getTables(null,null,"%",tables);
System.out.println("Tables in the Sales database:");
System.out.print('\t');
int i =0;
String [] tb = new String[10];
//String tba = new String("StudentRecord");
while(rs.next())
{
//System.out.print(rs.getString("TABLE_NAME") + " ");
tb = rs.getString("TABLE_NAME");
//i++;
System.out.println(tb);

if (!tb.equals("StudentRecord")) ;
{
//Create and load tables
stmt.executeUpdate("CREATE TABLE StudentRecord (StudentID VARCHAR(4), LastName"
+ " VARCHAR(25), FirstName VARCHAR(25), FinalGrade VARCHAR(1))");
}

}

stmt.executeUpdate
("INSERT INTO StudentRecord VALUES ('"+p1+"', '"+p2+"', '"+p3+"', '"+p4+"')");
stmt.close();


}// catch (SQLException se){System.out.println("SQL Exception"); }
catch (Exception e) {e.printStackTrace();}

callJsp("/Code/Assign5th2.jsp", request, response);

}

public void callJsp(String jsp,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(jsp);
dispatcher.forward(request, response);
}

}

Topic: question about linked list Previous Topic   Next Topic Topic: Question of the Day 2

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use