ms sql server 2008上与数据库连接的一些问题。编译器给出了以下错误“语法不正确”=“;”。我自己找不到任何错误。如果有人帮助我会很高兴。
所以,这是代码:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package sklad;
import java.sql.*;
import javax.swing.*;
/**
*
* @author Имба
*/
public class conexion {
// private static final String JDBCDriver ="com.microsoft.sqlserver.jdbc.SQLServerDriver";
// private static final String ConnectionStr = "jdbc:sqlserver:/localhost:1433;user=sa;password=asdf;databaseName = StoreDB";
public String user = "sa";
public String password = "asdf";
public String url = "jdbc:sqlserver://localhost:1433;
databaseName=StoreDB";
public Connection cn = null;
public Statement st = null;
public Statement Conectar()
{
try
{
Connection cn = DriverManager.getConnection(url,user,password);
st=cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
}
catch (SQLException i)
{
JOptionPane.showMessageDialog(null, i);
}
return st;
}
}
答案 0 :(得分:0)
将它放在一行中,没有换行符......
public String url = "jdbc:sqlserver://localhost:1433;databaseName=StoreDB";
答案 1 :(得分:0)
首先将url
放在一行,如下所示:
public String url = "jdbc:sqlserver://localhost:1433;databaseName=StoreDB";
Java不允许使用多行字符串文字。
除此之外,这个类设计很差,因为它本身不会清理。