.NET to Java
https://blog.csdn.net/ForrestLyu/article/details/77103678
https://blog.csdn.net/gebitan505/article/details/51753044
http://www.cnblogs.com/rabbityi/p/7079554.html
http://www.cnblogs.com/xiepeixing/p/4229221.html
Eclipse修改了代码,如果没有保存,运行的还是上次的未修改的状态,也就是说运行时不会自动帮你保存文件。(VS里的生成运行时,会自动帮你保存修改的未保存的文件)。
Eclipse没有单独的Build功能(VS里有生成),保存文件即编译,自动编译有错误的会显示出来。有些代码强制要求你放到try catch块中,比如sql操作,如果不放,编译不过,提示未处理的SQL异常。
Jdbc MySQL
package jdbdemo;
import java.sql.*;
public class dbHelper {
private String url="jdbc:mysql://localhost:3307/lims_test?useSSL=false";
private String user="root";
private String pwd="123456";
public void select()
{
try {
Connection con=DriverManager.getConnection(url, user, pwd);
Statement stm=con.createStatement();
String sql="select * from test_item";
ResultSet rs=stm.executeQuery(sql);
while(rs.next())
{
System.out.printf("%s %s \r\n", rs.getString("title"),rs.getString("code"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void delete(int id)
{
try {
Connection con=DriverManager.getConnection(url,user,pwd);
String sql="delete from test_item where id=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setInt(1, id); //从1开始
int cnt=ps.executeUpdate();
System.out.println(cnt);
ps.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void update(int id)
{
try {
Connection con=DriverManager.getConnection(url,user,pwd);
String sql="update test_item set title=? where id=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, "修改过后的名称");
ps.setInt(2, id); //从1开始
int cnt=ps.executeUpdate();
System.out.println(cnt);
ps.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void addnew()
{
try {
Connection con=DriverManager.getConnection(url,user,pwd);
String sql="insert into test_item(title,code,par,price,labid,rec_dt) values(?,?,?,?,?,?)";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, "标题N");
ps.setString(2, "Code3"); //从1开始
ps.setString(3, "15v");
ps.setDouble(4, 158.78);
ps.setInt(5, 7);
ps.setString(6, "2018-4-28 13:49");
int cnt=ps.executeUpdate();
System.out.println(cnt);
ps.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Java Project(控制台程序),添加引用jar,似乎不用注册驱动可直接运行。

Dynamic Web Project(J2EE),可以不用添加引用,直接把Jar放到lib目录下即可(或者放好后引用此文件),放在lib下,src下面的代码能自动识别好像,有错误时会显示。
src下面是源文件,WebContent下是web页面及资源文件。
jsp页面调用src下面的类,会提示“The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path”。
在build path/Lib,选择add lib,添加server runtime,选择配置好的tomcat服务器即可。
Jsp执行过程:Jsp->java(servlet)->class,第一次执行较慢。
浙公网安备 33010602011771号