Java动态Web项目 [英] Java Dynamic Web Project
本文介绍了Java动态Web项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了这个简单的java项目:
简单的JAVA项目代码:
Hi, i create this simple java project:
CODE OF SIMPLE JAVA PROJECT:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
class test{
public static void main(String[] args) throws SQLException {
// public boolean getConnection() throws SQLException{
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String server = "localhost";
String database = "Greco";
String jdbcUrl = "jdbc:sqlserver://"+server+";database="+database+";integratedSecurity=true";
try
{
Class.forName(driverName);
}
catch (ClassNotFoundException e1)
{
System.out.println("Class.forNameException; "+e1.getMessage());
}
Connection con = null;
try
{
// System.out.println("database connected");
con = DriverManager.getConnection(jdbcUrl);
// System.out.println("database connected");
// System.out.println("Connessione: "+con.toString());
}
catch(SQLException e)
{
System.out.println("database NOT connected");
System.out.println(""+e.getMessage());
}
Statement st = null;
ResultSet rs = null;
st = con.createStatement();
// st.executeQuery("select * from dbo.Fermentazione");
st.executeQuery("SELECT Top 1 [idSerbatoio],[nomeVino],[dataInizioFermentazione],[dataFineFermentazione]"+
"FROM [Greco].[dbo].[Fermentazione]"+
"where idSerbatoio = '1001'"+
"order by dataInizioFermentazione desc");
rs = st.getResultSet();
while(rs.next()) {
// JDBC columns starts at 1
System.out.print(rs.getString(1)+" ");
System.out.print(rs.getString(2)+" ");
System.out.print(rs.getString(3)+" ");
System.out.print(rs.getString(4)+" ");
// System.out.print(rs.getString(5)+" ");
// System.out.print(rs.getString(6)+"\n");
}
rs.close();
st.close();
con.close();
}
}
执行主类,此代码工作正常。但我会创建一个动态Web项目,所以我创建了一个动态Web项目,我把这个代码放在这样的方法中:
动态网站项目代码:
Executing the main class, this code works fine. But I would create a Dynamic Web Project, so i create a Dynamic Web Project and i put this code in a method like this:
CODE OF DYNAMIC WEB PROJECT:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ConnectionClass {
public String getConnection() throws SQLException{
Boolean connectionResult = false;
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String server = "localhost";
String database = "Greco";
String jdbcUrl = "jdbc:sqlserver://"+server+";database="+database+";integratedSecurity=true";
try
{
Class.forName(driverName);
}
catch (ClassNotFoundException e1)
{
System.out.println("Class.forNameException; "+e1.getMessage());
}
Connection con = null;
try
{
con = DriverManager.getConnection(jdbcUrl);
connectionResult=true;
}
catch(SQLException e)
{
System.out.println("database NOT connected");
System.out.println(""+e.getMessage());
}
Statement st = null;
ResultSet rs = null;
st = con.createStatement();
// st.executeQuery("select * from dbo.Fermentazione");
st.executeQuery("SELECT Top 1 [idSerbatoio],[nomeVino],[dataInizioFermentazione],[dataFineFermentazione]"+
"FROM [Greco].[dbo].[Fermentazione]"+
"where idSerbatoio = '1001'"+
"order by dataInizioFermentazione desc");
rs = st.getResultSet();
while(rs.next()) {
// JDBC columns starts at 1
System.out.print(rs.getString(1)+" ");
System.out.print(rs.getString(2)+" ");
System.out.print(rs.getString(3)+" ");
System.out.print(rs.getString(4)+" ");
// System.out.print(rs.getString(5)+" ");
// System.out.print(rs.getString(6)+"\n");
}
rs.close();
st.close();
con.close();
if(connectionResult) return "Connessione stabilita";
else return "Connessione non avvenuta";
}
}
现在,我该如何测试这个动态网络项目?我如何创建客户?
谢谢
Now, how can I test this dynamic web project? How can I create a client?
Thanks
推荐答案
参见http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse。 wst.webtools.doc.user%2Ftopics%2Fccwebprj.html [ ^ ]。
这篇关于Java动态Web项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文