1. struts2 中 連接資料庫報錯 ,是一個簡單的登陸界面,頁面上沒有報錯的情況,只是在登陸時,500的錯誤
public class ManagerLogin extends ActionSupport{
private Student student=null;
這兒出錯,你給student賦了null
當你在後面的excute方法中取得的student就是null
所以在ResultSet sqlSelect=Dbconnect.executeQuery("select stuName,password from student where stuName='"+student.getStuName()+"'and password='"+student.getPassword()+"'");
此處會報空指針異常錯誤。
2. Struts2+Spring+Hibernate3.1開發如何連接sql server 2008
hibernate就是用來搭建資料庫持久層的啊,,就用hibernete連啊,在hibernete.cfg裡面配置
<hibernate-configuration>
<session-factory>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="connection.url">
jdbc:sqlserver://localhost:1433;databaseName=dbname
</property>
<property name="connection.username">sa</property>
<property name="connection.password">pwd</property>
<property name="connection.driver_class">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<property name="myeclipse.connection.profile">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
</session-factory>
</hibernate-configuration>
3. sql2005 僅struts2框架 配資料庫連接池 失敗啊。 Cannot create PoolableConnectionFactory
首先確認你的密碼是不是對的。如果是對的:
所有程序 -> Microsoft SQL Server 2005 ->配置工具 ->SQL Server Configuration Manager
選擇:SQL Server 2005網路配置,然後選擇:MSSQLSERVER 的協議 ,然後將TCP/IP右鍵啟動,然後右鍵TCP/IP,選擇屬性,選擇IP地址,在IP1下邊的「已啟用」,選擇「是」...然後重啟服務..................OVER!
4. 請問,liferay集成struts2之後,在連接資料庫sql2005的時候出錯。是什麼問題。
配置類名出錯了。還有一種可能就是portlet沖突。
5. 用struts,寫一個連接sql2000資料庫怎麼寫
我正在用struts和sql server。
1、安裝sql server 並安裝sql server sp3補丁
2、安裝 Microsoft SQL Server 2000 Driver for JDBC
3、將\Microsoft SQL Server 2000 Driver for JDBC\lib下的3個jar文件加到classpath中。
4、將\Microsoft SQL Server 2000 Driver for JDBC\SQLServer JTA\sqljdbc.dll復制到\Microsoft SQL Server\MSSQL\Binn目錄下
5、在查詢分析器中運行\Microsoft SQL Server 2000 Driver for JDBC\SQLServer JTA\instjdbc.sql
6、編碼:
package db;
import java.sql.*;
public class DBConnection {
private Connection con;
private String driver;
private String url;
private String user;
private String pwd;
private String databaseType;
public Connection getConnection(){
return con;
}
public void setDriver(String tempDriver){
driver = tempDriver;
}
public String getDriver(){
return driver;
}
public void setURL(String tempURL){
url = tempURL;
}
public String getURL(){
return url;
}
public void setUser(String tempUser){
user = tempUser;
}
public String getUser(){
return user;
}
public void setPwd(String tempPwd){
pwd = tempPwd;
}
public String getPwd(){
return pwd;
}
public void setDatabaseType(String tempDatabaseType){
databaseType = tempDatabaseType;
}
public String getDatabaseType(){
return databaseType;
}
public DBConnection(String type){
if (type == "sql server"){
driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=YxdsWeb";
user = "sa";
pwd = "yxdsadmin";
databaseType = "sql server";
}
}
public DBConnection(String tempDriver,
String tempURL,
String tempUser,
String tempPwd,
String tempDatabaseType){
this.setDriver(tempDriver);
this.setURL(tempURL);
this.setUser(tempUser);
this.setPwd(tempPwd);
this.setDatabaseType(tempDatabaseType);
}
public Connection initConnection(){
if (driver == "" || url == "" || user == "" || databaseType == ""){
return con = null;
}
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url,user,pwd);
}catch(ClassNotFoundException e){
con = null;
System.out.println("driver error");
}catch(SQLException e){
con = null;
System.out.println("url error");
}catch(Exception e){
con = null;
}
return con;
}
public void close(){
if (con != null){
try{
con.close();
System.out.println("con.closed");
}catch(Exception e){
}
}
else
System.out.println("DBConnection.con has been closed");
}
}
6. struts2 的應用 資料庫是Mysql 提示sql語句錯誤
下面的語句在我的SQL2005資料庫中測試通過,你更改成你的表列和參數即可:
select top 2 I.username,J.password
from Authority as I,SalePerson as J
where I.password not in
(select top 1 password from Authority)
7. struts2 資料庫連接問題!~
package com.common;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConnection {
//創建連接
public static Connection getConnection() {
Connection DBconn = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://localhost:1433;databasename=Dept";
String user = "sa";
String password = "123";
DBconn = DriverManager.getConnection(url, user, password);
} catch (ClassNotFoundException e1) {
System.out.println("驅動程序載入錯誤");
} catch (SQLException e2) {
System.out.println("資料庫連接時錯誤");
} catch (Exception e3) {
e3.printStackTrace();
}
return DBconn;
}
//關門連接
public static void clear(Connection DBconn) {
if (DBconn != null) {
try {
DBconn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
8. javaweb開發 struts2關於資料庫連接的問題
你給的信息也不夠啊。下下來的東西,這個項目加到tomcat裡面了?
500的狀態碼說明內部伺服器錯誤。
這種東西自己寫也很簡單。
基於Struts2的使用JDBC 連接資料庫就行了。
使用mysql資料庫,然後下一個這個資料庫的管理軟體
9. struts2 怎麼連接sql2000 報錯
是:com.microsoft.jdbc.sqlserver.SQLServerDriver。
1.裝SQL補丁
2.裝JDBC驅動
3.把那3個JAR烤到工程的LIB裡面去。。
10. struts2連接MySQL出現HTTP Status 500 問題
你的資料庫連接函數寫在Action中,這是跟資料庫交互的部分。Action中不允許出現業務邏輯。
你說的錯誤在 st = (Statement) con.createStatement(); 搞錯了,上面都說了調用action函數則出錯:function.insert.execute(insert.java:23),執行插入的時候錯了。語法錯誤,沒試過插入會不會返回插入數據的條數,可以去掉試試。excute執行方法不止一個好像。錯在int count = st.executeUpdate(sql); 你用debug模式運行下,打斷點試試。