//加载驱动程序
Class.forName("com.mysql.jdbc.Driver").newInstance();
//建立连接
conn = DriverManager.getConnection("jdbc:mysql://localhost/ElectronicPolice?user=root&password=qqdiy0");
final String sql = "Insert Into VehicleLocate (headChar,VehiclelocateName,localFlag,specialFlag,specialType) values (?,?,?,?,?)";
PreparedStatement pstm = conn.prepareStatement(sql);
System.out.println("声明prepareStatement");
pstm.setString(1,dataIn.headChar);
pstm.setString(2,dataIn.vehicleLocateName);
pstm.setInt(3,dataIn.localFlag);
pstm.setInt(4,dataIn.specialFlag);
pstm.setString(5,dataIn.specialType);
System.out.println("将要执行SQL");
int count=pstm.executeUpdate();
System.out.println("执行完SQL");
if (count<1)
{
throw (new Exception());
}
pstm.close();
conn.close();
从我的程序剪下来的,不同数据库不同连接字符串。
Class.forName("com.mysql.jdbc.Driver").newInstance();
//建立连接
conn = DriverManager.getConnection("jdbc:mysql://localhost/ElectronicPolice?user=root&password=qqdiy0");
final String sql = "Insert Into VehicleLocate (headChar,VehiclelocateName,localFlag,specialFlag,specialType) values (?,?,?,?,?)";
PreparedStatement pstm = conn.prepareStatement(sql);
System.out.println("声明prepareStatement");
pstm.setString(1,dataIn.headChar);
pstm.setString(2,dataIn.vehicleLocateName);
pstm.setInt(3,dataIn.localFlag);
pstm.setInt(4,dataIn.specialFlag);
pstm.setString(5,dataIn.specialType);
System.out.println("将要执行SQL");
int count=pstm.executeUpdate();
System.out.println("执行完SQL");
if (count<1)
{
throw (new Exception());
}
pstm.close();
conn.close();
从我的程序剪下来的,不同数据库不同连接字符串。
解决方案 »
- SSH 中,除web层外,其它层如何取得当前Session的user对象
- jsp页面中如何判断文本框中输入的是数字,且小数点位数未超过六位
- 问一个关于long的简单问题.......
- 关于首页如何调用servlet
- 在jsp中如何将参数传给ShowModalDialog(),然后在ShowModalDialog弹出的对话框中提交Action处理
- SSH架构的论坛,如何实现发帖后跳转到刚发的帖子
- 请问这个网站的登陆框是怎么做的阿?请教高手!!!!
- javabean!!!解决给分!
- 为什么字符串超过700个汉字,插入oracle就会报错?
- IBM的webspere两个jsp页面进行数据传输时汉字无法正常显示的问题。
- 求教,JSP中,request.getParametersValues()方法怎么用?
- 大虾几句话帮菜鸟解决难题
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
//pubs为你的数据库的
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%> 这个是sql server的连接程序,你把它写在类里就行了,如果是测试的话,直接写在jsp页面中就可以!
最令我疑惑的就是,“2只”,不就你一个吗?还有那个呢??
//pubs为你的数据库的
你说的两个表都在pubs这个数据库用户里吧,那就不需要改